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

 
 
解题:要求什么寿命之和不能达到最大的寿命值,还要使得那个什么最小。。。最小。。。二分+树形dp。dp[u]表示u节点子树的最小代价。
 
dp[u] += min(dp[g[u][i].to],g[u][i].w);  表示要么不剪g[u][i]这条边,由其子树中的剪,要么剪g[u][i]这条边,子树不减,故取min就是。
 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 1000010
using namespace std;
const int maxn = ;
struct arc{
int to,w;
arc(int x = ,int y = ):to(x),w(y){}
};
vector<arc>g[maxn];
int n,m,dp[maxn];
void dfs(int u,int fa,int limit){
for(int i = ; i < g[u].size(); i++){
if(g[u][i].to == fa) continue;
dfs(g[u][i].to,u,limit);
if(g[u][i].w <= limit)
dp[u] += min(dp[g[u][i].to],g[u][i].w);
else dp[u] += dp[g[u][i].to];
}
if(g[u].size() == && g[u][].to == fa) dp[u] = INF;
}
int main() {
int i,j,u,v,w,lt,rt,mid,ans;
while(scanf("%d %d",&n,&m),n||m){
for(i = ; i <= n; i++)
g[i].clear();
for(lt = rt = ,i = ; i < n; i++){
scanf("%d %d %d",&u,&v,&w);
g[u].push_back(arc(v,w));
g[v].push_back(arc(u,w));
if(w > rt) rt = w;
}
ans = -;
while(lt <= rt){
mid = (lt+rt)>>;
memset(dp,,sizeof(dp));
dfs(,-,mid);
if(dp[] <= m){
ans = mid;
rt = mid-;
}else lt = mid+;
}
printf("%d\n",ans);
}
return ;
}
 

BNUOJ 7697 Information Disturbing的更多相关文章

  1. HDU 3586 Information Disturbing 树形DP+二分

    Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies ...

  2. HDU 3586.Information Disturbing 树形dp 叶子和根不联通的最小代价

    Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/ ...

  3. HDU - 3586 Information Disturbing 树形dp二分答案

    HDU - 3586 Information Disturbing 题目大意:从敌人司令部(1号节点)到前线(叶子节点)的通信路径是一个树形结构,切断每条边的联系都需要花费w权值,现在需要你切断前线和 ...

  4. 【题解】hdu 3586 Information Disturbing 二分 树形dp

    题目描述 Information DisturbingTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java ...

  5. HDU 3586 : Information Disturbing

    Problem Description In the battlefield , an effective way to defeat enemies is to break their commun ...

  6. HDU3586 Information Disturbing(树形DP)

    题目大概说一棵树有边权,要删掉一些边,使叶子到达不了树根1且删掉边的权和小于等于m,问删掉边中最大权的最小值能是多少. 考虑问题规模,与转移的时间复杂度,用这么个状态dp: dp[u][k]表示在u结 ...

  7. 树形DP+二分(Information Disturbing HDU3586)

    题意:给出一颗数,1结点代表司令部,叶子节点代表前线,边全值代表花费,然后需要在某些边放置一些炸弹,炸弹的能量不能小于该边的费用,且炸掉的总费用不能超过m问炸弹能力最小多少, 分析dfs+二分,二分枚 ...

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

    题目大意:一棵有n个节点的有根树,1为根节点,边带权,表示删掉这条边的代价.现在要删掉一些边,使叶子节点不能到达根节点.但是,每次删除的边的代价不能超过limit,删掉的边的总代价不能超过m,求最小的 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3586 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...

随机推荐

  1. Hdu 5358 First One (尺取法+枚举)

    题目链接: Hdu 5358 First One 题目描述: 数组a有n个元素,S[i,j]定义为a[i]+a[i+1]+.....+a[j],问:这个死东西等于多少? 解题思路: 二分肯定超,这个题 ...

  2. IOS - PDF合并 - 转

    来自:http://www.cnblogs.com/tx8899/p/4082749.html #pragma mark - Merge PDF - (void)mergePDF { NSArray  ...

  3. 12c pdb expdp use DATA_PUMP_DIR meet ORA-39145

    ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-39087: directory name DATA_ ...

  4. 441 Arranging Coins 排列硬币

    你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币.给定一个数字 n,找出可形成完整阶梯行的总行数.n 是一个非负整数,并且在32位有符号整型的范围内.示例 1:n ...

  5. joda日期格式转换

    public static String parseDateTime(String date,String formatFrom,String formatTo){ DateTimeFormatter ...

  6. 关于如何读取XML文件的一个简单方法

    在平时开发系统功能的时候,我们经常会碰到一些需求需要经常性的发生变化,比如 系统版本.更新日志 等等.这个时候用一个XML文件来替代数据库,就会变的简便很多. 前段时候我也正好需要改个需求,是关于客户 ...

  7. 关于OPPO手机的生存和程序员的发展

    关于程序员私下讨论最多的话题,除了哪个编程最牛逼之外,哪款品牌的手机最牛逼也是我们谈论最多的话题之一吧!有的喜欢罗永浩,自然就是锤粉:有的喜欢苹果,称它为工业时代最优美的艺术品:当然,我想也有很多的人 ...

  8. 了解java内存回收机制-博客导读

    此文作为读优质博客前的导读文 1.如何判断对象是否该回收 该对象是否被引用,是否处于不可达状态 2.对象的引用机制 强引用.软引用.弱引用.虚引用 3.垃圾回收机制如何回收.算法. 串行回收.并行回收 ...

  9. AlertDialog的实现

    课程Demo 重点解析自定义对话框 public class MainActivity extends AppCompatActivity { private Button bt1; private ...

  10. spring 整合struts

    1.例子:未被spring整合 struts.xml 的配置文件 <constant name="struts.enable.DynamicMethodInvocation" ...