Pagini recente » Cod sursa (job #591670) | Cod sursa (job #575670) | Cod sursa (job #2538116) | Cod sursa (job #1670245) | Cod sursa (job #1701188)
#include <bits/stdc++.h>
using namespace std;
int n,m,viz[50010];
vector<int> G[50010];
stack<int> stk;
void sort_top(int x)
{
viz[x] = 1;
for(int i = 0;i < G[x].size();++i)
if(!viz[G[x][i]])
sort_top(G[x][i]);
stk.push(x);
}
int main()
{
cin>>n>>m;
for (int i = 1;i <= m;++i)
{
int x, y;
cin >> x >> y;
G[x].push_back(y);
}
for(int i = 1;i <= n;++i)
if(!viz[i])
sort_top(i);
while(stk.size()){
cout<<stk.top()<<" ";
stk.pop();
}
return 0;
}