HDU 3586-Information Disturbing(树形dp)
题意:
n个节点的通信连接树,切断每个边有一定的花费,要你切断边,在总花费不超过m的前提,使所有的其他节点都不能和节点1(根)连通,切边时有花费上限,让你最小化这个上限。
分析:最小化最大值,想到二分,二分上限求符合条件的总花费和m比较。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF=<<;
const int mod = ;
struct edge{
int t,w;
};
vector<edge>e[];
int dp[],n,m,used[];
void dfs(int root,int limit){
used[root]=;
int f=,tmp=;
for(int i=;i<e[root].size();++i){
edge d=e[root][i];
int son=d.t;
int c=d.w;
if(used[son])continue;
f=;
dfs(son,limit);
if(c<=limit){
tmp+=min(dp[son],c);//小于上限,可切可不切
}
else tmp+=dp[son];//大于上限不能切断
}
if(f)
dp[root]=tmp;
else
dp[root]=INF;
}
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==&&m==)break;
int a;
for(int i=;i<=n;++i)
e[i].clear();
for(int i=;i<n-;++i){
edge b;
scanf("%d%d%d",&a,&b.t,&b.w);
e[a].push_back(b);
int tt=b.t;
b.t=a;
e[tt].push_back(b);
}
int l=,r=m,ff=-;
while(l<=r){
memset(dp,,sizeof(dp));
memset(used,,sizeof(used));
int mid=(l+r)>>;
dfs(,mid);
if(dp[]<=m){r=mid-;ff=mid;}
else l=mid+;
}
printf("%d\n",ff);
}
return ;
}
HDU 3586-Information Disturbing(树形dp)的更多相关文章
- HDU - 3586 Information Disturbing 树形dp二分答案
HDU - 3586 Information Disturbing 题目大意:从敌人司令部(1号节点)到前线(叶子节点)的通信路径是一个树形结构,切断每条边的联系都需要花费w权值,现在需要你切断前线和 ...
- 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+二分
Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies ...
- HDU 3586 Information Disturbing(二分+树形dp)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3586 题意: 给定一个带权无向树,要切断所有叶子节点和1号节点(总根)的联系,每次切断边的费用不能超 ...
- 【题解】hdu 3586 Information Disturbing 二分 树形dp
题目描述 Information DisturbingTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java ...
- hdu 3586 Information Disturbing(树形dp + 二分)
本文出自 http://blog.csdn.net/shuangde800 题目链接: hdu-3586 题意 给一棵n个节点的树,节点编号为1-n,根节点为1.每条边有权值,砍掉一条边要花费 ...
- HDU 3586 二分答案+树形DP判定
HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...
- [hdu3586]Information Disturbing树形dp+二分
题意:给出一棵带权无向树,以及给定节点1,总约束为$m$,找出切断与所有叶子节点联系每条边所需要的最小价值约束. 解题关键:二分答案,转化为判定性问题,然后用树形dp验证答案即可. dp数组需要开到l ...
- HDU 3586 Information Disturbing (二分+树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3586 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...
- HDU 3586 Information Disturbing (树形DP,二分)
题意: 给定一个敌人的通信系统,是一棵树形,每个节点是一个敌人士兵,根节点是commander,叶子是前线,我们的目的是使得敌人的前线无法将消息传到commander,需要切断一些边,切断每条边需要一 ...
随机推荐
- Mybatis 一对一、一对多、多对多关联之级联添加
示例项目:MIPO_CRM 一.一对一关联 示例:订单与销售机会 描述:在业务员与客户的联系人的联系记录中可以生成一条销售机会,而此条销售机会可生成一条订单,两者呈一对一关联. 1.表设计 oppor ...
- Matlab中添加搜索目录
一.问题来源 来自于一份大规模hash图像检索代码. 二.问题解析 2.1 添加目录 addpath('./utils/'); 2.2 添加目录及其子目录 addpath(genpath('./uti ...
- spoj 24
大数 #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> ...
- cf 283A
不能简单模拟(会超时) 运用一点小技巧 减少时间复杂度 #include <cstdio> #include <cstring> using namespace std; ...
- SaaS 公司如何应对 On-Call 挑战?
Cloud Insight 集监控.管理.计算.协作.可视化于一身,帮助所有 IT 公司,减少在系统监控上的人力和时间成本投入,让运维工作更加高效.简单.本文系国内 ITOM 行业领军企业 OneAP ...
- 【C++基础】关键字static 局部变量
1.局部变量 static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值: int test(int j){ static int i=10; i=i+j ...
- C++调用C#生成的DLL文件的各种问题
C++调用C#生成的DLL文件: 首先选择建立一个C#的类库,然后再按照需求编写需要的函数 之后,对于C++调用过程需要注意的几点: 1.使用#using <....some.dll>指出 ...
- Android工具:延展图片NinePatch
NinePatch能够对.png图片进行处理,生成一个.9.png格式的图片,图像拉伸操作时,图片就会有失真,而.9.png是Android里所支持的一种特殊的图片格式,可以实现部分拉伸. 制作图片方 ...
- POJ3687——Labeling Balls(反向建图+拓扑排序)
Labeling Balls DescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries ...
- MapReduce编程系列 — 4:排序
1.项目名称: 2.程序代码: package com.sort; import java.io.IOException; import org.apache.hadoop.conf.Configur ...