标签:class logs ++ span style ret for turn queue
1 int n,dg[K],topo[K]; 2 vector<int>mp[K]; 3 int topo_sort(void) 4 { 5 queue<int>q; 6 for(int i=1;i<=n;i++) 7 if(!dg[i]) q.push(i); 8 int res=1,cnt=0; 9 while(q.size()) 10 { 11 if(q.size()>1) res=0; 12 int x=q.front();q.pop(); 13 topo[cnt++]=x; 14 for(int i=0;i<mp[x].size();i++) 15 if(--dg[mp[x][i]]==0) q.push(mp[x][i]); 16 } 17 if(cnt!=n) return -1; 18 return res; 19 }
标签:class logs ++ span style ret for turn queue
原文地址:http://www.cnblogs.com/weeping/p/6978695.html