POJ 2631 Roads in the North
来源:互联网 发布:淘宝装修自定义源代码 编辑:程序博客网 时间:2024/05/22 15:21
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=10000+100;int len,ans,cnt=0,p[maxn],son[maxn],head[maxn],vis[maxn],weigh[maxn][maxn];struct node{ int u,v,next;}node[2*maxn];void add(int u,int v){ node[cnt].u=u;node[cnt].v=v; node[cnt].next=head[u]; head[u]=cnt++; node[cnt].u=v;node[cnt].v=u; node[cnt].next=head[v]; head[v]=cnt++;}void dfs(int u){ vis[u]=1; for(int i=head[u];i!=-1;i=node[i].next) { if(u==1) son[u]=0; int v=node[i].v; if(vis[v]) continue; dfs(v); son[u]=max(son[u],son[v]+weigh[u][v]); if(u==1) p[len++]=son[1]; }}int main(){ int u,v,w; memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(son,0,sizeof(son)); while(scanf("%d%d%d",&u,&v,&w)!=EOF) { weigh[u][v]=w; weigh[v][u]=w; add(u,v); } ans=(1<<30); dfs(1); sort(p,p+len); printf("%d",p[len-1]+p[len-2]); printf("\n"); return 0;}
0 0
- POJ - 2631 Roads in the North
- poj 2631 Roads in the North
- POJ 2631 Roads in the North
- B - Roads in the North POJ-2631
- POJ 2631Roads in the North【裸题】
- 【POJ 2631 Roads in the North】
- 【POJ】[2631]Roads in the North
- POJ 2631 Roads in the North 笔记
- Roads in the North POJ
- POJ 2631 Roads in the North POJ 1985 Cow Marathon
- POJ 2631 Roads in the North(树形dp)
- POJ 2631 Roads in the North 树的直径
- 【树的直径】 POJ 2631 Roads in the North
- POJ 2631 Roads in the North(树的直径)
- poj 2631 Roads in the North(裸树的直径)
- POJ 2631 -- Roads in the North【树的直径 && 裸题】
- POJ 2631 Roads in the North(树的直径)
- 【POJ】2631 - Roads in the North(树的直径)
- 源码-印度式乘法口诀表(“双十九”)的PL/SQL实现
- LeetCode 17. Letter Combinations of a Phone Number高效解法
- ContextLoaderListener和ServletDispatcher
- 安卓时间相关的广播(Intent.ACTION_TIME_TICK)
- Qt学习之路(57): 文本文件读写
- POJ 2631 Roads in the North
- [从头读历史] 第301节 山海经 其实这不是一本神话书
- 查一年内的数据 SQL语句
- Android资源类型之Animation
- Oracle同义词创建及其作用
- Qt学习之路(58): 进程间交互
- ie bugs
- Map(一)之HashMap(java8)
- SQL group by分组查询