POJ 2631 Roads in the North
2016-07-13 16:25
253 查看
#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; }
相关文章推荐
- Sharepoint部署配置向导
- Postgresql 异步流复制
- 部署SharePoint 2013
- Windows 10中启用Bitlocker加密
- Exchange 2013恢复已禁用用户邮箱
- Java匿名类浅析
- 两中方式找出Excel中相同和不同的数据
- 用JavaScript编写业务逻辑?
- UVA 11584 Partitioning by Palindromes
- 查看计算机信息
- 天津招聘Jave,网页设计师,3D建模工程师
- springMVC web项目 数据库用户名密码加密解密
- 部署Orchester 2012 R2
- Windows端Apache的域名映射
- JZOJ 1422. 猴子摘桃
- AD账户UserAccountControl对应的值
- 安卓时间相关的广播(Intent.ACTION_TIME_TICK)
- SnapKit配置过程记录
- iOS 屏幕尺寸、分辨率、适配
- 安装SCCM2012 R2