日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/21 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【题解】hdu 3586 Information Disturbing 二分 树形dp 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

Information Disturbing
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4003 Accepted Submission(s): 1391

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

大意

題目大意:給定n個敵方據點,1為司令部,其他點各有一條邊相連構成一棵樹,每條邊都有一個權值cost表示破壞這條邊的費用,葉子節點為前線。現要切斷前線和司令部的聯系,每次切斷邊的費用不能超過上限limit,問切斷所有前線與司令部聯系所花費的總費用少于m時的最小limit。1<=n<=1000,1<=m<=1000000

思路

  • 二分+樹形dp

  • 二分可能的limit,再判斷該limit下的花費是否符合m;
  • dp: 對于一個節點u及其子節點v,要切斷u子樹下所有葉子節點與u的聯系,有兩種方式.
  • 設dp[u]表示切斷u子樹下所有葉子節點與u的聯系的最小花費
  • 不切斷u->v,$dp[u]+=dp[v]$;
  • 切斷u->v,$dp[u]+=dis(u,v)$;
  • 代碼

    #include<cstdio> #include<string> #include<vector> #include<cstring> #include<iostream> #define re register int using namespace std; const int maxn=1e3+50; inline int read(){int x=0,w=1;char ch=getchar();while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();if(ch=='-') w=-1,ch=getchar();while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-48,ch=getchar();return x*w; } int head[maxn<<1]; long long dp[maxn]; int tot=1,INF=1e6; struct data{int to,nxt;long long w; }edge[maxn<<1]; void DFS(int u,int fa,int lim){int flag=0;dp[u]=0;for(int i=head[u];i;i=edge[i].nxt){int v=edge[i].to;if(v!=fa){flag=1;DFS(v,u,lim);if(edge[i].w<=lim)dp[u]+=min(dp[v],edge[i].w);elsedp[u]+=dp[v];}} if(!flag) dp[u]=INF; } inline void add(int u,int v,int w){edge[tot].to=v;edge[tot].w=w;edge[tot].nxt=head[u];head[u]=tot++; } int main(){int MAXX=-1;int n,m;while(~scanf("%d%d",&n,&m)) { // cout<<n<<m<<endl;if(n==0&&m==0) break;tot=1;memset(head,0,sizeof(head));for(re i=1;i<n;++i) {int a,b,w;a=read(),b=read(),w=read();add(a,b,w);add(b,a,w);MAXX=max(MAXX,w);}int l=0,r=MAXX,ans=-1,mid;while(l<=r) {//cout<<endl;mid=(l+r)>>1;DFS(1,-1,mid);//cout<<l<<" "<<r<<endl;//cout<<dp[1]<<endl;if(dp[1]<=m){ans=mid;r=mid-1;}else l=mid+1;}printf("%d\n",ans);}return 0; }/* 5 5 1 3 2 1 4 3 3 5 5 4 2 6 0 0 */

    ?

    ?

    轉載于:https://www.cnblogs.com/bbqub/p/9073077.html

    總結

    以上是生活随笔為你收集整理的【题解】hdu 3586 Information Disturbing 二分 树形dp的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 国产欧美日韩另类 | 国产午夜精品无码一区二区 | 国产黄色一级 | 色噜噜综合| 图片区视频区小说区 | 妖精视频在线观看 | 情趣五月天 | 亲子乱一区二区三区 | 老司机午夜免费福利 | 日本美女毛片 | 青青青国产精品一区二区 | 精品国产一区二区三区日日嗨 | 九九热精品在线 | 亚洲一区二区三区四区在线播放 | 久久久精品中文字幕 | 99在线免费 | 欧美日a| 成人a在线观看 | 日本aⅴ在线观看 | 91蜜桃传媒精品久久久一区二区 | 日韩五十路 | 少妇特黄一区二区 | 太久av| av大片免费观看 | 米奇av | 日本三级在线 | 性做久久久久久久免费看 | 免费观看黄色一级片 | 96视频在线观看 | 精品69| 波多野结衣啪啪 | 欧美自拍偷拍第一页 | 国产精品香蕉在线 | 亚洲第一a| 亚洲情涩 | 又色又爽又黄gif动态图 | 天堂网av中文字幕 | 日日干综合 | 色综合视频在线观看 | 四虎婷婷 | 国产污片在线观看 | 九色91porny| 成人传媒| а 天堂 在线 | 大奶子在线观看 | 女生脱裤子让男生捅 | 日韩久久一区二区 | 亚洲欧美日韩国产精品 | 国产农村老头老太视频 | 69色综合| 欧洲a级片 | 艳母在线视频 | 口爆吞精一区二区三区 | 国产精品国产a级 | 欧美性猛交xxxx乱大交退制版 | 亚洲男人的天堂在线观看 | 一区二区三区四区五区视频 | 日韩久久免费视频 | 久草综合在线 | 欧美激情免费在线观看 | 成年人免费网站 | 男女无遮挡做爰猛烈视频 | 日本免费网站 | 伊人蕉久影院 | www视频免费观看 | 国产乱码一区 | 亚洲成人免费影院 | 小宝贝真紧h军人h | 66av欧美| 国产伦精品一区二区三区妓女下载 | 亚洲高清网 | 中文字幕一区二区三区日韩精品 | 成人h动漫精品一区二区无码 | 成人免费福利视频 | 日本一区二区视频在线观看 | 欧美性生活一区二区三区 | 在线日韩视频 | caoporn成人 | 黄色片免费网站 | 国产农村老头老太视频 | 国产剧情久久久 | 中国无码人妻丰满熟妇啪啪软件 | 欧美精品黄 | 国产乱子伦一区二区 | 国产精品69毛片高清亚洲 | 尤物视频在线观看国产性感 | 一区二区视频在线观看 | 欧美一级黄色片 | 国产精品天天av精麻传媒 | 中国一级特黄录像播放 | 中文字幕精品久久久久人妻红杏1 | 国产一区二区精品在线观看 | 国产第一区第二区 | wwwww国产| 91精品91久久久中77777老牛 | 亚洲a人 | 草草影院第一页yycc.com | 天天做天天干 | 中文字幕在线导航 |