Pagini recente » Autentificare | Borderou de evaluare (job #1681194) | Cod sursa (job #293697) | Diferente pentru problema/editor intre reviziile 13 si 12 | Cod sursa (job #3159409)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int viz[50005], st[50005];
int n, top, x, y, m;
vector<int> a[50005];
void DFS(int i)
{
viz[i] = 1;
for(auto w : a[i])
if(viz[w] == 0) DFS(w);
st[++top] = i;
}
int main()
{
int i;
fin >> n >> m;
for(i=1;i<=m;i++)
{
fin >> x >> y;
a[x].push_back(y);
}
for(i=1;i<=n;i++)
if(viz[i] == 0) DFS(i);
for(i=n;i>=1;i--)
fout << st[i] << " ";
fin.close();
fout.close();
return 0;
}