Pagini recente » Cod sursa (job #398749) | Cod sursa (job #1279347) | simulare_de_oni_4 | Cod sursa (job #2407550) | Cod sursa (job #1968091)
#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() {
dfs(1);
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;
}