structEdge { int to, next; } e[maxm * 2]; int c1, head[maxn], in[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; }
priority_queue<int> Q; vector<int> ans; voidtopsort(){ for (int i = 1; i <= n; ++i) if (!in[i]) Q.push(i); while (!Q.empty()) { int u = Q.top(); Q.pop(); ans.push_back(u); for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (--in[v] == 0) Q.push(v); } } }
voidinit(){ fill(head, head + maxn, -1); fill(in, in + maxn, 0); c1 = 0; ans.clear(); }
voidwork(){ cin >> n >> m; init(); for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; add_edge(y, x); ++in[x]; } topsort(); if (ans.size() < n) return (void) (cout << "Impossible!\n"); reverse(ans.begin(), ans.end()); for (auto u : ans) cout << u << " "; cout << "\n"; }