Pagini recente » Cod sursa (job #537358) | Cod sursa (job #504127) | Cod sursa (job #2961482) | Cod sursa (job #2219053) | Cod sursa (job #2705388)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
vector<int> g[50001];
list<int> ord;
bool viz[50001];
void dfs(int x)
{
viz[x] = 1;
for(int i : g[x])
if(!viz[i])
dfs(i);
ord.push_front(x);
}
int main()
{
int x, y;
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> x >> y;
g[x].push_back(y);
}
for(int i = 1; i <= n; i++)
if(!viz[i])
dfs(i);
for(int i : ord)
fout << i << " ";
return 0;
}