Pagini recente » Cod sursa (job #679693) | Cod sursa (job #843850) | Cod sursa (job #992407) | Cod sursa (job #3255978) | Cod sursa (job #2646748)
// intai se invata fluxul si apoi sortarea topologica
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
const int INF = 2e9;
const int N = 5e4;
int n, m;
vector <int> G[5 + N];
vector <int> sol;
bool viz[5 + N];
void DFS(int node) {
viz[node] = true;
for(auto it : G[node]) {
if(!viz[it])
DFS(it);
}
sol.push_back(node);
}
int main() {
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
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);
}
for(int i = 1; i <= n; i++) {
if(!viz[i]) DFS(i);
}
reverse(sol.begin(), sol.end());
for(auto it : sol) printf("%d ", it);
return 0;
}