题意:

n个节点的通信连接树,切断每个边有一定的花费,要你切断边,在总花费不超过m的前提,使所有的其他节点都不能和节点1(根)连通,切边时有花费上限,让你最小化这个上限。

分析:最小化最大值,想到二分,二分上限求符合条件的总花费和m比较。

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <vector>
  9. #include <string>
  10. #include <cctype>
  11. #include <complex>
  12. #include <cassert>
  13. #include <utility>
  14. #include <cstring>
  15. #include <cstdlib>
  16. #include <iostream>
  17. #include <algorithm>
  18. using namespace std;
  19. typedef pair<int,int> PII;
  20. typedef long long ll;
  21. #define lson l,m,rt<<1
  22. #define pi acos(-1.0)
  23. #define rson m+1,r,rt<<11
  24. #define All 1,N,1
  25. #define read freopen("in.txt", "r", stdin)
  26. const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
  27. const int INF=<<;
  28. const int mod = ;
  29. struct edge{
  30. int t,w;
  31. };
  32. vector<edge>e[];
  33. int dp[],n,m,used[];
  34. void dfs(int root,int limit){
  35. used[root]=;
  36. int f=,tmp=;
  37. for(int i=;i<e[root].size();++i){
  38. edge d=e[root][i];
  39. int son=d.t;
  40. int c=d.w;
  41. if(used[son])continue;
  42. f=;
  43. dfs(son,limit);
  44. if(c<=limit){
  45. tmp+=min(dp[son],c);//小于上限,可切可不切
  46. }
  47. else tmp+=dp[son];//大于上限不能切断
  48. }
  49. if(f)
  50. dp[root]=tmp;
  51. else
  52. dp[root]=INF;
  53. }
  54. int main()
  55. {
  56. while(~scanf("%d%d",&n,&m)){
  57. if(n==&&m==)break;
  58. int a;
  59. for(int i=;i<=n;++i)
  60. e[i].clear();
  61. for(int i=;i<n-;++i){
  62. edge b;
  63. scanf("%d%d%d",&a,&b.t,&b.w);
  64. e[a].push_back(b);
  65. int tt=b.t;
  66. b.t=a;
  67. e[tt].push_back(b);
  68. }
  69. int l=,r=m,ff=-;
  70. while(l<=r){
  71. memset(dp,,sizeof(dp));
  72. memset(used,,sizeof(used));
  73. int mid=(l+r)>>;
  74. dfs(,mid);
  75. if(dp[]<=m){r=mid-;ff=mid;}
  76. else l=mid+;
  77. }
  78. printf("%d\n",ff);
  79. }
  80. return ;
  81. }

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. 如何在Ubuntu下搭建Android NDK开发环境

    1 搭建Android SDK开发环境 参考在在Ubuntu下搭建Android SDK开发环境(图文)首先在Ubuntu下搭建Android SDK开发环境. 2 下载NDK开发包 打开官网: ht ...

  2. 漫话C++0x(五)—- thread, mutex, condition_variable

    熟悉C++98的朋友,应该都知道,在C++98中没有thread, mutex, condition_variable这些与concurrency相关的特性支持,如果需要写多线程相关程序,都要借助于不 ...

  3. POJ 2275 Flipping Pancake

    点我看题目 题意 : 按我自己的理解就是,给你n个数,按照从上到下排列,现在让你进行一系列的操作,让你将数按照从大到小排好. 思路 : 比赛的时候以为要用记录路径的搜索,当时没什么把握,所以没做,今天 ...

  4. 【BZOJ 1046】 1046: [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < ...

  5. java thread类和runable

    java thread 类其实和其他类是一样的.有自己的属性和方法.以及有一个重写的run方法 不同的是:必须重写run()方法. run()方法是线程thread启动后cpu调用运行的程序代码. r ...

  6. xcode 预编译头文件

    xcode 预编译头文件 cocos2d-prefix.pch  #import <Foundation/Foundation.h>

  7. mybatis整合redis

    mybatis默认缓存是PerpetualCache,可以查看一下它的源码,发现其是Cache接口的实现:那么我们的缓存只要实现该接口即可. 编写Redis需要用的2个工具类   RedisUtil. ...

  8. C++ eof()函数相关应用技巧分享

    C++编程语言中的很多功能在我们的实际应用中起着非常大的作用.比如在对文件文本的操作上,就可以用多种方式来实现.在这里我们介绍的C++ eof()函数就是其中一个比较常用的基本函数. 在使用C/C++ ...

  9. Qt xcode wrapper Qios OpenFly

    https://github.com/richardmg/QtWrapper https://github.com/richardmg/qios https://github.com/richardm ...

  10. adb开启不了解决方案

    原文地址: adb开启不了解决方案 - vaecer - 博客频道 - CSDN.NET http://blog.csdn.net/vaecer/article/details/45894643   ...