标签:
[2016-02-17][UVA][10305][Ordering Tasks]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; typedef long long LL; #define CLR(x,y) memset((x),(y),sizeof((x))) #define FOR(x,y,z) for(int (x)=(y);(x)<(z);(x)++) #define FORD(x,y,z) for(int (x)=(y);(x)>=(z);(x)--) #define FOR2(x,y,z) for((x)=(y);(x)<(z);(x)++) #define FORD2(x,y,z) for((x)=(y);(x)>=(z);(x)--) const int maxn = 100 + 10; int n,m,g[maxn][maxn],vis[maxn],topo[maxn],t; void dfs( int u){ vis[u] = 1; FOR(v,1,n+1){ if (g[u][v] && !vis[v]){ dfs(v); } } topo[--t] = u; } void toposort(){ t = n; CLR(vis,0); FOR(u,1,n+1) if (!vis[u]) dfs(u); } int main(){ while (~ scanf ( "%d%d" ,&n,&m) && (n || m)){ int a,b; CLR(g,0); FOR(i,0,m){ scanf ( "%d%d" ,&a,&b); g[a][b] = 1; } toposort(); printf ( "%d" ,topo[0]); FOR(i,1,n){ printf ( " %d" ,topo[i]); } puts ( "" ); } return 0; } |
[2016-02-17][UVA][10305][Ordering Tasks]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/5199594.html