const int MAXN = 100001; vector<int> G[MAXN], ans; bool vis[MAXN]; void dfs(int u) { vis[u] = true; REP(i, G[u].size()) { int v = G[u][i]; if (!vis[v]) dfs(v); } ans.push_back(u); } int main() { // freopen("in.txt", "r", stdin); int n, m, a, b; while (~RII(n, m)) { CLR(vis, false); ans.clear(); FE(i, 1, n) G[i].clear(); REP(i, m) { RII(a, b); G[b].push_back(a); } FE(i, 1, n) { if (!vis[i]) dfs(i); } FED(i, ans.size() - 1, 0) { printf("%d ", ans[i]); } puts(""); } return 0; }
Coder-Strike 2014 - Round 1__Giving Awards
原文地址:http://blog.csdn.net/wty__/article/details/24550667