标签:style blog http color java os io for
5 5 1 3 2 1 4 3 3 5 5 4 2 6 0 0
3
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define INF 1000010 15 using namespace std; 16 const int maxn = 1001; 17 struct arc{ 18 int to,w; 19 arc(int x = 0,int y = 0):to(x),w(y){} 20 }; 21 vector<arc>g[maxn]; 22 int n,m,dp[maxn]; 23 void dfs(int u,int fa,int limit){ 24 for(int i = 0; i < g[u].size(); i++){ 25 if(g[u][i].to == fa) continue; 26 dfs(g[u][i].to,u,limit); 27 if(g[u][i].w <= limit) 28 dp[u] += min(dp[g[u][i].to],g[u][i].w); 29 else dp[u] += dp[g[u][i].to]; 30 } 31 if(g[u].size() == 1 && g[u][0].to == fa) dp[u] = INF; 32 } 33 int main() { 34 int i,j,u,v,w,lt,rt,mid,ans; 35 while(scanf("%d %d",&n,&m),n||m){ 36 for(i = 0; i <= n; i++) 37 g[i].clear(); 38 for(lt = rt = 1,i = 1; i < n; i++){ 39 scanf("%d %d %d",&u,&v,&w); 40 g[u].push_back(arc(v,w)); 41 g[v].push_back(arc(u,w)); 42 if(w > rt) rt = w; 43 } 44 ans = -1; 45 while(lt <= rt){ 46 mid = (lt+rt)>>1; 47 memset(dp,0,sizeof(dp)); 48 dfs(1,-1,mid); 49 if(dp[1] <= m){ 50 ans = mid; 51 rt = mid-1; 52 }else lt = mid+1; 53 } 54 printf("%d\n",ans); 55 } 56 return 0; 57 }
BNUOJ 7697 Information Disturbing,布布扣,bubuko.com
BNUOJ 7697 Information Disturbing
标签:style blog http color java os io for
原文地址:http://www.cnblogs.com/crackpotisback/p/3904781.html