标签:exchange seve bit i++ break ott col init set
#include<bits/stdc++.h> using namespace std; const int maxn=1005;struct node{ int to,next,va; }e[2*maxn]; int n,m,tot; int dp[maxn],head[maxn]; void Inite(){ tot=0; memset(head,-1,sizeof(head)); } void addedge(int u,int v,int w){ e[tot].to=v; e[tot].va=w; e[tot].next=head[u]; head[u]=tot++; } void DFS(int pa,int u,int limit){ dp[u]=0; int flag=0; for(int i=head[u];i!=-1;i=e[i].next){ int v=e[i].to; if(pa==v) continue; flag=1; DFS(u,v,limit); if(e[i].va>limit) dp[u]+=dp[v]; else dp[u]+=min(dp[v],e[i].va); } if(flag==0) dp[u]=100001; } bool check(int limit){ DFS(0,1,limit); if(dp[1]>m) return false; else return true; } void Solve(){ int l=0,r=m+1; for(int i=1;i<=100;i++){ int mid=(l+r)>>1; if(check(mid)) r=mid; else l=mid; } if(check(l)) printf("%d\n",l); else if(check(r)) printf("%d\n",r); else printf("-1\n"); } int main() { while(~scanf("%d%d",&n,&m)){ if(n==0&&m==0) break; Inite(); for(int i=2;i<=n;i++){ int u,v,va; scanf("%d%d%d",&u,&v,&va); addedge(u,v,va); addedge(v,u,va); } Solve(); } return 0; }
Information Disturbing hdu-3586
标签:exchange seve bit i++ break ott col init set
原文地址:http://www.cnblogs.com/zgglj-com/p/7769155.html