<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PC9wPgo8cHJlIGNsYXNzPQ = "brush: java; "> /************************************* * *********************************** File Name: 10305four. cpp Author: yubo Mail: yuzibode@126.com Created Time: June 02, 2014 Monday seconds learning focus: referenceJohn has n tasks to do. unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. inputThe input will consist of several instances of the problem. each instance begins with a line containing two integers, 1 <=n <= 100 and m. n is the number of tasks (numbered from 1 to n) and m is the number of direct precedence relations between tasks. after this, there will be m lines with two integers I and j, representing the fact that task I must be executed before task j. an instance with n = m = 0 will finish the input. outputFor each instance, print a line with n integers representing the tasks in a possible order of execution. sample Input5 41 22 31 31 50 0 Sample Output1 4 2 5 3: *************************************** * ********************************/# include # Include # Include # Include Using namespace std; # define MAXN 105 // have time according to text to writestruct ArcNode {int to; struct ArcNode * next ;}; ArcNode * List [MAXN]; int n, m; int counts [MAXN]; int output [MAXN]; void toposort () {stack S; memset (output, 0, sizeof (output); for (int I = 0; I To; counts [f] --; if (counts [f] = 0) {s. push (f) ;}temp = temp-> next ;}} if (bcycle) printf ("The Network has a cycle \ n "); else {for (int l = 0; l Next; delete temp; temp = List [I] ;}} int main () {// freopen ("in.txt", "r", stdin); int u, v; while (scanf ("% d", & n, & m) {if (! N &&! M) break; memset (List, 0, sizeof (List); memset (counts, 0, sizeof (counts); for (int I = 0; I To = v; temp-> next = NULL; if (temp = NULL) List [u] = temp; else {temp-> next = List [u]; list [u] = temp ;}} ArcNode * temp = new ArcNode; toposort (); del ();}}