Pagini recente » Cod sursa (job #1664256) | Cod sursa (job #1312521) | Cod sursa (job #2262460) | Cod sursa (job #2756903) | Cod sursa (job #2639953)
#include <bits/stdc++.h>
#define oo 500005
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
vector < int > g[oo], L;
int n, m, x, y;
bitset < oo > c;
void dfs(int k){
c[k] = true;
for(int i = 0; i < g[k].size(); i++){
int vec = g[k][i];
if(!c[vec])
dfs(vec);
}
L.push_back(k);
}
int main(){
in>>n>>m;
for(int i = 1; i <= m; i++){
in>>x>>y;
g[x].push_back(y);
}
for(int i = 1; i <= n; i++)
if(!c[i])
dfs(i);
for(int i = L.size() - 1; i >= 0; i--)
out<<L[i]<<" ";
}