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 <queue> #include <algorithm> #include <vector> using namespace std; int main() { const int maxn = 200; int n,val,num; while(cin>>n && n) { num = n; int idx=0; vector<int> g[maxn]; while (n--) { idx++; while(cin>>val && val) g[idx].push_back(val); } queue<int> que; //int *rudu = new int[num+1]; //memset(rudu,0,sizeof(rudu)); int rudu[maxn];memset(rudu,0,sizeof(rudu)); for (int i = 1 ; i <= num ; i++ ) for (int j = 0 ; j< g[i].size() ; j++) rudu[g[i][j]]++; //for (int i=1 ; i<=num ; i++) // cout<<rudu[i]<<" "; //cout<<endl; for (int i=1 ; i<=num ; i++) { if (rudu[i]==0) { que.push(i); break; } } int tmp; while(!que.empty()) { tmp = que.front(); cout<<tmp; que.pop(); for (int i = 0 ; i< g[tmp].size(); i++) if(--rudu[g[tmp][i]] == 0 ) {que.push(g[tmp][i]);cout<<" ";} } cout<<endl; } //system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator