BNUOJ 7697 Information Disturbing
Information Disturbing
This problem will be judged on HDU. Original ID: 3586
64-bit integer IO format: %I64d Java class name: Main
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 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
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
#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的更多相关文章
- HDU 3586 Information Disturbing 树形DP+二分
Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies ...
- HDU 3586.Information Disturbing 树形dp 叶子和根不联通的最小代价
Information Disturbing Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/ ...
- HDU - 3586 Information Disturbing 树形dp二分答案
HDU - 3586 Information Disturbing 题目大意:从敌人司令部(1号节点)到前线(叶子节点)的通信路径是一个树形结构,切断每条边的联系都需要花费w权值,现在需要你切断前线和 ...
- 【题解】hdu 3586 Information Disturbing 二分 树形dp
题目描述 Information DisturbingTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java ...
- HDU 3586 : Information Disturbing
Problem Description In the battlefield , an effective way to defeat enemies is to break their commun ...
- HDU3586 Information Disturbing(树形DP)
题目大概说一棵树有边权,要删掉一些边,使叶子到达不了树根1且删掉边的权和小于等于m,问删掉边中最大权的最小值能是多少. 考虑问题规模,与转移的时间复杂度,用这么个状态dp: dp[u][k]表示在u结 ...
- 树形DP+二分(Information Disturbing HDU3586)
题意:给出一颗数,1结点代表司令部,叶子节点代表前线,边全值代表花费,然后需要在某些边放置一些炸弹,炸弹的能量不能小于该边的费用,且炸掉的总费用不能超过m问炸弹能力最小多少, 分析dfs+二分,二分枚 ...
- HDU-3586 Information Disturbing(树形DP+删边)
题目大意:一棵有n个节点的有根树,1为根节点,边带权,表示删掉这条边的代价.现在要删掉一些边,使叶子节点不能到达根节点.但是,每次删除的边的代价不能超过limit,删掉的边的总代价不能超过m,求最小的 ...
- HDU 3586 Information Disturbing (二分+树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3586 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...
随机推荐
- 转-UIButton定义和设置圆角
//login button // .h 中定义 UIButton *_loginBtn; @property (strong,nonatomic)UIButton *loginBtn; // .m ...
- Android开发学习——android数据存储
Android的存储 Android中的数据存储方式及其存储位置 SharedPrefrence存储 1). 位置 /data/data/packageName/shared_pr ...
- jstat命令-帮助优化java性能
jstat命令使用 jstat命令可以查看堆内存各部分的使用量,以及加载类的数量.命令的格式如下: jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]
- 微信小程序之多行文本省略号
最近在捣鼓小程序,期间遇到的问题,踩过的坑,也是在网上各种搜.这里也说下我解决的问题,方便大家. 在小程序首页显示文本列表的时候,为了美观,不希望把所有的文本都显示出来,希望是显示前几行(比如前3行, ...
- Java线程-线程、程序、进程的基本概念
线程 与进程相似,但线程是一个比进程更小的执行单位.一个进程在其执行的过程中可以产生多个线程. 与进程不同的是同类的多个线程共享同一块内存空间和一组系统资源,所以系统在产生一个线程,或是在各个线程之间 ...
- 学习 微信小程序 大神不要笑
- HTML5小時鐘
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/T ...
- AttributeError: 'list' object has no attribute 'extends' && list详解
拼写错误 是extend 而不是extends 出错demo: In [27]: c = [2,3] In [28]: c.extends([5]) ------------------------ ...
- bat运行当前路径下程序
批处理中获取当前路径的方法可能有好几种,具体有几种我没有研究过,本文只是对其中的两种之间的差别进行简单说明 本文涉及的两个当前路径标示为:%cd%.%~dp0 注:我的系统是win7旗舰版,其它系统没 ...
- Axis1.4框架 实现webservice服务器和客户端
一:软件环境 win7旗舰版, Eclipse,JDK1.6,tomcat6.0,Axis1.4的包. 至于Axis1.4包网上可以下载,如果是在找不到可以留言给我. 二:摘要 将解压后的 axis- ...