Pagini recente » Cod sursa (job #421314) | Cod sursa (job #1565216) | Cod sursa (job #201368) | Cod sursa (job #1816631) | Cod sursa (job #1968093)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 5e5 + 10;
int n, m;
int used[nmax];
vector < int > g[nmax];
vector < int > topo;
void input() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++i) {
int x, y; scanf("%d %d", &x, &y);
g[x].push_back(y);
}
}
void dfs(int node) {
used[node] = 1;
for (auto &it: g[node]) {
if (used[it]) continue;
dfs(it);
}
topo.push_back(node);
}
void topo_sort() {
for (int i = 1; i <= n; ++i)
if (!used[i]) dfs(i);
reverse(topo.begin(), topo.end());
}
void output() {
for (auto &it: topo)
printf("%d ", it);
printf("\n");
}
int main() {
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
input();
topo_sort();
output();
return 0;
}