Topic Link http://poj.org/problem?id=2367
Test instructions is a series of relationships, sorted by these relational topologies.
#include <cstdio>#include<cstring>#include<queue>#include<vector>#include<algorithm>using namespacestd;Const intmaxn= $;intans;intN;int inch[MAXN];//Record Entry degreeintNUM[MAXN];//Record Answersvector<int>E[maxn];//Record EdgevoidTopo_sort ()//Topological sorting{Queue<int>Q; for(intI=1; i<=n; i++) if(!inch[i]) {Q.push (i); inch[i]=-1; } while(!Q.empty ()) { intnow=Q.front (); Num[ans]=Now ; Ans++; Q.pop (); for(intI=0; I<e[now].size (); i++) if(inch[e[now][i]]>0) inch[e[now][i]]--; for(intI=1; i<=n; i++) if(!inch[i]) {inch[i]=-1; Q.push (i); } } return ;}intMain () { while(~SCANF ("%d",&N) {memset (num,0,sizeof(num)); memset (inch,0,sizeof(inch)); for(intI=0; i<maxn;i++) e[i].clear (); Ans=0; for(intI=1; i<=n; i++) { intx; while(SCANF ("%d",&x)) {if(!x) Break; E[i].push_back (x); inch[x]++; } sort (E[i].begin (), E[i].end ()); } topo_sort (); printf ("%d", num[0]); for(intI=1; i<n; i++) printf ("%d", Num[i]); Puts (""); } return 0;}
Topological sequencing of graph theory POJ 2367 Genealogical Tree