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. 暑期训练狂刷系列——Lightoj 1084 - Winter bfs

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1084 题目大意: 有n个点在一条以零为起点的坐标轴上,每个点最多可以移动k, ...

  2. Maven环境搭建操作记录

    Maven官方网站: http://maven.apache.org/index.html Maven下载地址: http://maven.apache.org/download.cgi Maven历 ...

  3. 209 Minimum Size Subarray Sum 大于给定和最短子数组

    给定一个含有 n 个正整数的数组和一个正整数 s , 找到一个最小的连续子数组的长度,使得这个子数组的数字和 ≥  s .如果不存在符合条件的子数组,返回 0.举个例子,给定数组 [2,3,1,2,4 ...

  4. js几个逻辑运算符的形象概括

    “&&”是逻辑与操作符,只有“&&”两边值同时满足(同时为真),整个表达式值才为真. b>a && b<c    //“&& ...

  5. 一些常用的meta标签及其作用

    声明文档使用的字符编码  <meta charset='utf-8'>优先使用 IE 最新版本和 Chrome  <meta http-equiv="X-UA-Compat ...

  6. 手机酷派4G5316 5313s 黑砖 求转成功 9008端口 9006端口 少走弯路选对镜像

    首先要有资料 里面有教程  http://pan.baidu.com/s/1bpjxP6n 1.用其他手机 or u 盘往sd卡放进“强制进入下载模式的文件” 2. 驱动 3.刷机工具 下载镜像   ...

  7. 解决国内无法安装android sdk的问题

    在使用 Android SDK Manager 的时候,主要会连接到两个地址 dl.google.com 和 dl-ssl.google.com,key发现这两个地址都是无法正常访问的,如何解决呢? ...

  8. 使用GetLogicalDrives获取卷标

    #include<stdio.h> #include<windows.h> int main() { DWORD dwLogical= GetLogicalDrives(); ...

  9. jquery attr的属性

    在JS中设置节点的属性与属性值用到setAttribute(),获得节点的属性与属性值用到getAttribute(),而在jquery中,用一个attr()就可以全部搞定了,赞一个先 ^^ jque ...

  10. vue-router scrollBehavior的用法

    问题: 使用keep-alive标签后部分安卓机返回缓存页位置不精确问题 解决方案: <div id="app"> <keep-alive> <rou ...