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 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
 
Author
alpc86
 
Source
 
Recommend
zhouzeyong   |   We have carefully selected several similar problems for you:  3583 3584 3585 3587 3588 
 
题意:有一棵n个节点的树,现在需要删除一些边使得叶子节点和根(1)不是联通的,删除的总边权不超过m,并且最大边权最小。
思路:dp[u]表示u的子节点与u不相连的代价。<u,v>w,dp[u]+=min(dp[v],w)。当最大边权为x时,需要进行判断<u,v>w,如果w比x大的话,只能dp[u]+=dp[v]。所以二分最大边权。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-8
typedef long long ll;
typedef pair<int,int > P;
const int N=2e5+,M=2e6+;
const int inf=0x3f3f3f3f;
const ll INF=1e18+,mod=1e9+;
struct edge
{
int from,to;
ll w;
int next;
};
edge es[M];
int cnt,head[N];
ll dp[N];
void init()
{
cnt=;
memset(head,-,sizeof(head));
}
void addedge(int u,int v,ll w)
{
cnt++;
es[cnt].from=u,es[cnt].to=v;
es[cnt].w=w;
es[cnt].next=head[u];
head[u]=cnt;
}
void dfs(int u,int fa,ll mid)
{
dp[u]=0LL;
int child=;
for(int i=head[u]; i!=-; i=es[i].next)
{
edge e=es[i];
if(e.to==fa) continue;
child++;
dfs(e.to,u,mid);
if(e.w>mid) dp[u]+=dp[e.to];
else dp[u]+=min(dp[e.to],e.w);
}
if(!child) dp[u]=inf;
}
int main()
{
int n;
ll m;
while(~scanf("%d%lld",&n,&m))
{
if(n==&&m==) break;
init();
ll l=inf,r=-inf;
for(int i=; i<n; i++)
{
int u,v;
ll w;
scanf("%d%d%lld",&u,&v,&w);
l=min(l,w),r=max(r,w);
addedge(u,v,w);
addedge(v,u,w);
}
ll ans=;
while(l<=r)
{
ll mid=(l+r)>>;
dfs(,,mid);
if(dp[]<=m) r=mid-,ans=mid;
else l=mid+;
}
if(ans) printf("%d\n",ans);
else printf("-1\n");
}
return ;
}

树形dp

HDU 3586.Information Disturbing 树形dp 叶子和根不联通的最小代价的更多相关文章

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

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

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

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

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

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3586 题意: 给定一个带权无向树,要切断所有叶子节点和1号节点(总根)的联系,每次切断边的费用不能超 ...

  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(树形dp + 二分)

    本文出自   http://blog.csdn.net/shuangde800 题目链接:   hdu-3586 题意 给一棵n个节点的树,节点编号为1-n,根节点为1.每条边有权值,砍掉一条边要花费 ...

  6. HDU 3586 二分答案+树形DP判定

    HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...

  7. [hdu3586]Information Disturbing树形dp+二分

    题意:给出一棵带权无向树,以及给定节点1,总约束为$m$,找出切断与所有叶子节点联系每条边所需要的最小价值约束. 解题关键:二分答案,转化为判定性问题,然后用树形dp验证答案即可. dp数组需要开到l ...

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

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

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

    题意: 给定一个敌人的通信系统,是一棵树形,每个节点是一个敌人士兵,根节点是commander,叶子是前线,我们的目的是使得敌人的前线无法将消息传到commander,需要切断一些边,切断每条边需要一 ...

随机推荐

  1. (Python基础)字符串操作

    以下是我在学习过程中用的一些常用字符串操作的相关列子和具体注释,感兴趣的可以自己动手试试看 #字符串操作 name = 'my name is keep' print(name.capitalize( ...

  2. scrapy爬去京东书籍信息

    # -*- coding: utf-8 -*- import scrapy import urllib import json from copy import deepcopy class JdSp ...

  3. orcal - 多表查询

    SQL1999语法标准 CROSS JOIN 产生笛卡尔积 SELECT * from EMP CROSS JOIN dept; NATURAL JOIN 自然连接 相同列 SELECT * from ...

  4. 发布python包

    写python程序时常常要导入各种包,使用其中的模块或功能.我们如果有可以复用的功能或模块也可以发布成包,并安装在自己或他人电脑上,以供自己或别人使用.python发布包的步骤如下: 一.首先为模块创 ...

  5. Nginx配置跨域支持功能

    跨域是前端开发中经常会遇到的问题,前端调用后台服务时,通常会遇到 No 'Access-Control-Allow-Origin' header is present on the requested ...

  6. Unity添加多个可视镜头Preview功能(二)

    制作好并摆放好镜头以后,在Preview.cs里添加一个time单个镜头移动时间的变量,并在PreviewEditor下绘制在Inspector面板下. 然后,添加一个FollowPreviewPat ...

  7. 天池医疗AI大赛支持有感

    从去年大概11月份开始一直到现在,大部分的精力在天池医疗AI大赛的研发和支持上面,也算深度支持了20几只复赛参赛队伍的复赛进程.总的感觉其实与现在媒体宣传的"中国成为AI大国"ba ...

  8. 第一次C语言程序设计

    C语言程序实验报告 实验项目: 1.字符与ASCII码 2.运算符与表达式的应用 3.顺序结构应用程序 4.数学函数的算法描述 5.鸡兔同笼的算法描述 6.确定坐标的算法描述 姓名:张时锋 实验地点: ...

  9. spring AOP capbilities and goal

    Spring AOP 是用纯JAVA 实现的. 不需借助JAVA代码在编译处理阶段来实现. Spring 是在运行期实现的.AOP的实现可以在编译,加载,运行三个阶段来实现:Spring AOP 也不 ...

  10. com.android.support:design

    Error:Could not find com.android.support:design:27.3.1.Required by: project :app Please install the ...