UVaLive6039 Uva1668 Let's Go Green
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了UVaLive6039 Uva1668 Let's Go Green,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1435字,纯文字阅读大概需要3分钟。
内容图文
一开始考虑所有边都是单独的一条路径
然后尽量多的合并
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<algorithm> 5 #include<iostream> 6 7usingnamespace std; 8 9void setIO(conststring& s) { 10 freopen((s + ".in").c_str(), "r", stdin); 11 freopen((s + ".out").c_str(), "w", stdout); 12} 13 template<typename Q> Q read(Q& x) { 14staticchar c, f; 15for(f = 0; c = getchar(), !isdigit(c); ) if(c == ‘-‘) f = 1; 16for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - ‘0‘; 17if(f) x = -x; 18return x; 19} 20 template<typename Q> Q read() { 21static Q x; read(x); return x; 22} 2324constint N = 100000 + 10; 25int main() { 26#ifdef DEBUG 27 freopen("in.txt", "r", stdin); 28 freopen("out.txt", "w", stdout); 29#endif3031staticint du[N], mx[N]; 32int T = read<int>(); 33for(int cas = 1; cas <= T; cas++) { 34 memset(du, 0, sizeof du); 35 memset(mx, 0, sizeof mx); 36int ans = 0; 37int u, v, w, n = read<int>(); 38for(int i = 1; i < n; i++) { 39 read(u), read(v), read(w); 40 du[u] += w, du[v] += w; 41 mx[u] = max(mx[u], w); 42 mx[v] = max(mx[v], w); 43 ans += w; 44 } 4546for(int u = 1; u <= n; u++) { 47if((mx[u] << 1) <= du[u]) ans -= du[u] >> 1; 48else ans -= du[u] - mx[u]; 49 } 5051 printf("Case #%d: %d\n", cas, ans); 52 } 5354return0; 55 }
' ref='nofollow'>UVaLive6039 Uva1668 Let's Go Green
原文:http://www.cnblogs.com/showson/p/5077097.html
内容总结
以上是互联网集市为您收集整理的UVaLive6039 Uva1668 Let's Go Green全部内容,希望文章能够帮你解决UVaLive6039 Uva1668 Let's Go Green所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。