题意:

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)的更多相关文章

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

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

  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+二分

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

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

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

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

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

  6. hdu 3586 Information Disturbing(树形dp + 二分)

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

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

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

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

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

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

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

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

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

随机推荐

  1. 微软职位内部推荐-Senior SDE for Cloud Platform

    微软近期Open的职位: Microsoft Launched the public cloud service-Azure in China on May 2013, Cosmos is the k ...

  2. 0ffice365 Calendar API

    Calendar REST API in Office 365 APIs Preview http://msdn.microsoft.com/EN-US/library/office/dn792114 ...

  3. parsing html in asp.net

    http://stackoverflow.com/questions/5307374/parsing-html-page-in-asp-net http://htmlagilitypack.codep ...

  4. MS SQL Server时间常用函数

    SQLServer时间日期函数详解,SQLServer,时间日期, 1.      当前系统日期.时间 select getdate() 2. dateadd      在向指定日期加上一段时间的基础 ...

  5. TWaver3D入门探索——3D拓扑图之人在江湖

    俗话说,有人的地方就有江湖,江湖就是帮派林立错综复杂的关系网.今天我们就来展示这样一个小小的江湖. 故事背景 崇祯末年,民不聊生,烽烟四起-- 江湖都是有背景的,我们的3D江湖也需要一个背景.江湖就是 ...

  6. gif格式的图片不能存在与包含js目录的路径中?

    如题:gif格式的图片不能存在与包含js目录的路径中?是我的设置问题?还是真不能存在于js目录中. 今天纠结了一下午,某个项目中的效果就是出不来,找了差不多两个半小时... 在D盘新建一个js和jss ...

  7. Aimp3的播放列表 按评分排序 落雨

    如图,添加评分选项,并保存,就可以在下图的选项里找到此选项,并按评分排序 效果图如下:还可以倒置,迅速使评分高的音乐排在播放列表的前面位置!! 转自百度知道: http://zhidao.baidu. ...

  8. docker 通过commit方法创建镜像(Tomcat+Java+Scala)

    前一阵试了试写Dockerfile创建docker image,但有时全靠Dockerfile写实在有些难度,退而求其次试一试使用commit来创建镜像: 想了想干脆创建一个Java+Scala+To ...

  9. Python 异常结构

    http://flyheaven.blog.163.com/blog/static/7401172201193085243920/ 1.Python内建异常体系结构 The class hierarc ...

  10. ASP.NET 访问 MySql

    1. 首先需要安装mysql, 脚本之家下载地址: http://www.jb51.net/softs/2193.html 或者去mysql.com官网都可以,一路next,安装好后,有个简单配置,提 ...