BNUOJ 7697 Information Disturbing

Information Disturbing

Time Limit: 3000ms

Memory Limit: 65536KB

This problem will be judged on HDU. Original ID: 3586
64-bit integer IO format: %I64d      Java class name: Main

In the battlefield , an effective way to defeat enemies is to break their communication system.
The information department told you that there are n enemy soldiers and their network which have n-1 communication routes can cover all of their soldiers. Information can exchange between any two soldiers by the communication routes. The number 1 soldier is the total commander and other soldiers who have only one neighbour is the frontline soldier.
Your boss zzn ordered you to cut off some routes to make any frontline soldiers in the network cannot reflect the information they collect from the battlefield to the total commander( number 1 soldier).
There is a kind of device who can choose some routes to cut off . But the cost (w) of any route you choose to cut off can’t be more than the device’s upper limit power. And the sum of the cost can’t be more than the device’s life m.
Now please minimize the upper limit power of your device to finish your task.

Input

The input consists of several test cases. 
The first line of each test case contains 2 integers: n(n<=1000)m(m<=1000000).
Each of the following N-1 lines is of the form:
ai bi wi
It means there’s one route from ai to bi(undirected) and it takes wi cost to cut off the route with the device.
(1<=ai,bi<=n,1<=wi<=1000)
The input ends with n=m=0.

Output

Each case should output one integer, the minimal possible upper limit power of your device to finish your task. 
If there is no way to finish the task, output -1.

Sample Input

5 5
1 3 2
1 4 3
3 5 5
4 2 6
0 0

Sample Output

3

Source

2010 ACM-ICPC Multi-University Training Contest(15)——Host by NUDT

解题:要求什么寿命之和不能达到最大的寿命值,还要使得那个什么最小。。。最小。。。二分+树形dp。dp[u]表示u节点子树的最小代价。

dp[u] += min(dp[g[u][i].to],g[u][i].w);  表示要么不剪g[u][i]这条边,由其子树中的剪,要么剪g[u][i]这条边,子树不减,故取min就是。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #include <stack>
13 #define LL long long
14 #define INF 1000010
15 using namespace std;
16 const int maxn = 1001;
17 struct arc{
18     int to,w;
19     arc(int x = 0,int y = 0):to(x),w(y){}
20 };
21 vector<arc>g[maxn];
22 int n,m,dp[maxn];
23 void dfs(int u,int fa,int limit){
24     for(int i = 0; i < g[u].size(); i++){
25         if(g[u][i].to == fa) continue;
26         dfs(g[u][i].to,u,limit);
27         if(g[u][i].w <= limit)
28             dp[u] += min(dp[g[u][i].to],g[u][i].w);
29         else dp[u] += dp[g[u][i].to];
30     }
31     if(g[u].size() == 1 && g[u][0].to == fa) dp[u] = INF;
32 }
33 int main() {
34     int i,j,u,v,w,lt,rt,mid,ans;
35     while(scanf("%d %d",&n,&m),n||m){
36         for(i = 0; i <= n; i++)
37             g[i].clear();
38         for(lt = rt = 1,i = 1; i < n; i++){
39             scanf("%d %d %d",&u,&v,&w);
40             g[u].push_back(arc(v,w));
41             g[v].push_back(arc(u,w));
42             if(w > rt) rt = w;
43         }
44         ans = -1;
45         while(lt <= rt){
46             mid = (lt+rt)>>1;
47             memset(dp,0,sizeof(dp));
48             dfs(1,-1,mid);
49             if(dp[1] <= m){
50                 ans = mid;
51                 rt = mid-1;
52             }else lt = mid+1;
53         }
54         printf("%d\n",ans);
55     }
56     return 0;
57 }

BNUOJ 7697 Information Disturbing

时间: 2024-10-08 18:56:33

BNUOJ 7697 Information Disturbing的相关文章

HDU 3586 Information Disturbing 树形DP+二分

Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies is to break their communication system.The information department told you that there are n enemy soldiers and their network which have n-1 communicati

hdu 3586 Information Disturbing (树形dp)

Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1722    Accepted Submission(s): 641 Problem Description In the battlefield , an effective way to defeat enemies is to bre

HDU 3586.Information Disturbing 树形dp

Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 3205    Accepted Submission(s): 1137 Problem Description In the battlefield , an effective way to defeat enemies is to bre

Hdu Information Disturbing

Hdu Information Disturbing Description In the battlefield , an effective way to defeat enemies is to break their communication system. The information department told you that there are n enemy soldiers and their network which have n-1 communication

Information Disturbing hdu-3586

Problem Description In the battlefield , an effective way to defeat enemies is to break their communication system.The information department told you that there are n enemy soldiers and their network which have n-1 communication routes can cover all

HDU 3586 Information Disturbing

二分+树形DP验证. 答案是通过二分查找得到的,对于每一次二分到的值,进行验证,是否可行. 可以用树形DP来求解所有叶子节点不能向根节点传送消息的最小费用,dp[i] 表示 节点i 的子树的叶子结点都不能向i传送消息的最小费用,这样很容易递推. #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<map> #include<vector>

HDU-3586 Information Disturbing(树形DP+删边)

题目大意:一棵有n个节点的有根树,1为根节点,边带权,表示删掉这条边的代价.现在要删掉一些边,使叶子节点不能到达根节点.但是,每次删除的边的代价不能超过limit,删掉的边的总代价不能超过m,求最小的limit的可能取值. 题目分析:二分枚举limit,定义状态dp(u)表示将u与它管辖的叶子节点失去联系所需要的总代价,则: dp(u)+=min(dp(son),e[i].w),e[i].w<=limit: dp(u)+=dp(son)  e[i].w>limit: 代码如下: # inclu

HDU 3586 Information Disturbing (树形DP,二分)

题意: 给定一个敌人的通信系统,是一棵树形,每个节点是一个敌人士兵,根节点是commander,叶子是前线,我们的目的是使得敌人的前线无法将消息传到commander,需要切断一些边,切断每条边需要一定的power,而我们有一台具有m点power的机器,问在使用此机器切断敌人通信系统的情况下,使得所切断边的最大边权达到最小是多少?(m<=100w,n<=1000) 思路: 其实就是要求所切断的边的最小瓶颈边.由于m比较大,不好枚举或者DP.但是他们具有线性的关系,就是瓶颈边越大,肯定越容易有解

HDU 3586 Information Disturbing (二分+树形dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3586 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏这条边的费用,叶子节点为前线.现要切断前线和司令部的联系,每次切断边的费用不能超过上限limit,问切断所有前线与司令部联系所花费的总费用少于m时的最小limit.1<=n<=1000,1<=m<=10^6 dp[i]表示i节点为root的这个子树所破坏的最少费用,if(cost[i]