标签:style blog color os io strong 数据 for
vector
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <climits> #include <cstring> #include <stack> #include <vector> #include <algorithm> #define ll long long using namespace std; const int INF = 0x3f3f3f3f; struct edge{ int ev,w; edge(int a,int b):ev(a),w(b){ } }; vector <edge> elist[400000]; bool vis[400000]; int s, ans; void DFS(int fv,int dis){ if (dis > ans){ ans = dis; s = fv; } vis[fv] = true; int size = elist[fv].size(); int ev,w; for (int i = 0; i < size; ++i){ ev = elist[fv][i].ev; w = elist[fv][i].w; if (vis[ev]) continue; DFS(ev,dis + w); } } int main(){ int N,M; int fv,ev,w; char dir[10]; while(EOF != scanf("%d%d",&N,&M)){ for (int i = 1; i <= N; ++i) elist[i].clear(); for (int i = 1; i <= M; ++i){ scanf("%d%d%d%s",&fv,&ev,&w,dir); elist[fv].push_back(edge(ev,w)); elist[ev].push_back(edge(fv,w)); } memset(vis,0,sizeof(vis)); s = ans = 0; DFS(1,0); memset(vis,0,sizeof(vis)); ans = 0; DFS(s,0); printf("%d\n",ans); } return 0; }
POJ1985 DFS【STL__vector_的应用】,布布扣,bubuko.com
标签:style blog color os io strong 数据 for
原文地址:http://www.cnblogs.com/wushuaiyi/p/3898609.html