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/