Description: The Topology Sorting in Liu lujia's book has not changed at all. However, the output of the test sample may be different from that of the test sample, but there is nothing to do with it, if a qualified output is met, You Can # include <iostream> # include <cstdio> # include <cstring> using namespace std; int flag, n, m; int topo [110], num [110], s [110] [110]; bool dfs (int site) {num [site] =-1; for (int I = 1; I <= n; I ++) if (s [site] [I] & (num [I] <0 | (! Num [I] &! Dfs (I) return false; num [site] = 1; topo [-- flag] = site; return true;} bool toposort () {flag = n; memset (num, 0, sizeof (num); for (int I = 1; I <= n; I ++) if (! Num [I] &! Dfs (I) return false; return true;} int main () {// freopen ("a.txt", "r", stdin); int x, y, count; while (scanf ("% d", & n, & m )! = EOF) {if (! N &&! M) break; memset (s, 0, sizeof (s); for (count = 0; count <m; count ++) {scanf ("% d ", & x, & y); s [x] [y] = 1;} if (toposort () for (count = 0; count <n-1; count ++) printf ("% d", topo [count]); printf ("% d \ n", topo [count]);} return 0 ;}