Pagini recente » Cod sursa (job #2389444) | Cod sursa (job #2956098) | Cod sursa (job #3289112) | Cod sursa (job #1563528) | Cod sursa (job #2866921)
#include <bits/stdc++.h>
#define oo 5555555
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int e[50005],top;
vector<int>v[50005];
int viz[50005];
int n,m;
void Sorttop(int x)
{
viz[x]=1;
for(auto w:v[x])
if(viz[w]==0) Sorttop(w);
e[++top]=x;
}
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
fin>>x>>y;
v[x].push_back(y);
}
for(int i=1;i<=n;i++)
if(viz[i]==0) Sorttop(i);
for(int i=n;i>=1;i--)
fout<<e[i]<<" ";
return 0;
}