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,需要切断一些边,切断每条边需要一 ...
随机推荐
- 如何在Ubuntu下搭建Android NDK开发环境
1 搭建Android SDK开发环境 参考在在Ubuntu下搭建Android SDK开发环境(图文)首先在Ubuntu下搭建Android SDK开发环境. 2 下载NDK开发包 打开官网: ht ...
- 漫话C++0x(五)—- thread, mutex, condition_variable
熟悉C++98的朋友,应该都知道,在C++98中没有thread, mutex, condition_variable这些与concurrency相关的特性支持,如果需要写多线程相关程序,都要借助于不 ...
- POJ 2275 Flipping Pancake
点我看题目 题意 : 按我自己的理解就是,给你n个数,按照从上到下排列,现在让你进行一系列的操作,让你将数按照从大到小排好. 思路 : 比赛的时候以为要用记录路径的搜索,当时没什么把握,所以没做,今天 ...
- 【BZOJ 1046】 1046: [HAOI2007]上升序列
1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...
- java thread类和runable
java thread 类其实和其他类是一样的.有自己的属性和方法.以及有一个重写的run方法 不同的是:必须重写run()方法. run()方法是线程thread启动后cpu调用运行的程序代码. r ...
- xcode 预编译头文件
xcode 预编译头文件 cocos2d-prefix.pch #import <Foundation/Foundation.h>
- mybatis整合redis
mybatis默认缓存是PerpetualCache,可以查看一下它的源码,发现其是Cache接口的实现:那么我们的缓存只要实现该接口即可. 编写Redis需要用的2个工具类 RedisUtil. ...
- C++ eof()函数相关应用技巧分享
C++编程语言中的很多功能在我们的实际应用中起着非常大的作用.比如在对文件文本的操作上,就可以用多种方式来实现.在这里我们介绍的C++ eof()函数就是其中一个比较常用的基本函数. 在使用C/C++ ...
- Qt xcode wrapper Qios OpenFly
https://github.com/richardmg/QtWrapper https://github.com/richardmg/qios https://github.com/richardm ...
- adb开启不了解决方案
原文地址: adb开启不了解决方案 - vaecer - 博客频道 - CSDN.NET http://blog.csdn.net/vaecer/article/details/45894643 ...