Ultraviolet A 10305

Source: Internet
Author: User


<喎?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 ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.