Codeforces 61D. Eternal Victory 树的性质
来源:互联网 发布:niconico网络无法连接 编辑:程序博客网 时间:2024/04/29 14:20
从起点开始访问所有的节点,要求边权和最小。可以发现除了从起点到终点一条路径,剩余每条边都访问了两次,所以问题变成了寻找从起点开始的最长路径,答案就是边权和*2-最长路径。
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int INF=1e9+9;const int maxn=111111;int n;long long ans;struct EDGE{ int to; int w; int next;}edges[maxn*2];int edge;int head[maxn];void init(){ memset(head,-1,sizeof(head)); memset(edges,0,sizeof(edges)); edge=0; ans=0;}void addedge(int u,int v,int c){ edges[edge].w=c;edges[edge].to=v;edges[edge].next=head[u];head[u]=edge++; edges[edge].w=c;edges[edge].to=u;edges[edge].next=head[v];head[v]=edge++;}long long dfs(int u,int dad,long long flow){ long long ret=flow; int v,w; for (int i=head[u];i!=-1;i=edges[i].next) { v=edges[i].to; w=edges[i].w; if (v!=dad) { ret=max( ret, dfs(v,u,flow+w) ); } } return ret;}int main(){ int n; cin>>n; init(); for (int i=1;i<n;i++) { int u,v,w; cin>>u>>v>>w; addedge(u,v,w); ans+=w*2; } long long ret=dfs(1,0,0); cout<<ans-ret<<endl; return 0;}
- Codeforces 61D. Eternal Victory 树的性质
- codeforces 61D Eternal Victory 树形DP
- Codeforces Beta Round #57 (Div. 2) D. Eternal Victory
- hrbust 1750 Eternal Victory(树+广搜 类似找树的直径...)
- 【CodeForces 686 D. 】 【树的重心性质】
- Hrbust 1750 Eternal Victory【贪心+Dfs】
- Codeforces Round #245 (Div. 2)D(树的性质+状压+dfs)
- CodeForces 827D 浅谈最小生成树性质解析及题目性质分析
- CodeForces 21D - Traveling Graph 欧拉回路的性质+状态压缩DP
- Codeforces Round #235 (Div. 2) / 410D Roman and Numbers (带有整除性质的数位DP)
- CodeForces 471D MUH and Cube Walls KMP算法+串的取差性质
- codeforces The Eternal Immortality 题解
- codeforces 869BThe Eternal Immortality
- Codeforces #353D (Div. 2) STL+数据结构性质
- Codeforces 873 D Merge Sort(归并排序性质)
- Codeforces 869B. The Eternal Immortality
- CodeForces 869B The Eternal Immortality
- codeforces 869B The Eternal Immortality
- Adapter
- 2013编程之美 传话游戏
- poj 1006 hdu1370 Biorhythms
- SVN如何修改用户密码
- Transact-SQL语言零基础
- Codeforces 61D. Eternal Victory 树的性质
- SQLServer汉字转全拼音函数
- linux安装 rar
- ubuntu 编码
- Maven环境的搭建与idea配置
- C#中的WebBrowser控件的使用
- 跳出while/for循环
- 索引和全表的开销权衡问题
- 如何查看计算机端口状态 .