UVa 10305 ordering Tasks: Topology sort template

Source: Internet
Author: User

10305-ordering Tasks

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1246

Template problems. Pay attention to the output backwards.

Template:

 01./*0.022s*/02.  
#include <bits/stdc++.h> 04.using namespace std;  
05.const int MAXN = 101;  
07.list<int> LI[MAXN];  
08.bool VIS[MAXN];  
09.int ANS[MAXN], CNT; 11.void dfs (int i) 12.  
{Vis[i] = true;        15 if (Li[i].size ()).            for (List<int>::iterator iter = Li[i].begin (); Iter!= li[i].end (); ++iter) 16.  
if (!vis[*iter]) DFS (*iter);  
ans[cnt++] = i;  
18.} 19. 20.int Main () 21.  
{. int n, M, I, A, b;    while (scanf ("%d%d", &n, &m), N) 24.        {. if (M = = 0) 26.                {for (i = 1; I <= n; ++i) 28. printf ("%d%c", I, (i = = n?)  
": 10));  
Continue;        30.} 31.  
for (i = 0; i < MAXN ++i) li[i].clear ();  
memset (Vis, 0, sizeof (VIS));  
CNT = 0;        while (m--) 35.  
{scanf ("%d%d", &a, &b); Panax Li[a].push_bac.K (b);        38.} 39.            for (i = 1; I <= n; ++i) 40.  
if (!vis[i]) DFS (i);            for (i = n-1 i; i.) 42.  
printf ("%d", ans[i]);  
printf ("%d\n", Ans[0]);    44.} 45.  
return 0; +.} 

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.