Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助,WA#include<iostream> #include<vector> using namespace std; vector<short>edge[50001]; short visited[10001]; int V,E; void DFS(int u)/*反向边DFS*/ { visited[u] = 1; for(int i=0;i<edge[u].size();i++) { if(!visited[edge[u][i]]) { DFS(edge[u][i]); } } } int main() { while(cin >> V >> E) { int i,u; int f,t; for(i=0;i<V+1;i++) edge[i].clear(); for(i=0;i<E;i++) { cin >> f >> t;/* f->t */ edge[t].push_back(f);/*反向邻接表*/ } for(u=1;u<=V;u++)/*枚举所有顶点*/ { memset(visited,0,sizeof(visited));/*置visited为0*/ DFS(u); /*检验是否所有点都已经遍历过*/ bool flag = true; for(i=1;i<=V;i++) { if(!visited[i]) { flag = false; break; } } if(flag) { cout << u << endl; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator