Pagini recente » Cod sursa (job #944678) | Cod sursa (job #1163790) | Cod sursa (job #1137567) | Cod sursa (job #2979974) | Cod sursa (job #1130726)
//#include <iostream>
#include<fstream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
#define maxn 500001
int a,b,m,n,grad[maxn];
vector<int> g,v[maxn];
void topsort(){
for(int i=1;i<=n;i++){
if(grad[i]==0){
g.push_back(i);
}
}
for(int i=0;i<g.size();i++){
for(int j=0;j<v[g[i]].size();j++){
grad[v[g[i]][j]]--;
if(grad[v[g[i]][j]]==0){
g.push_back(v[g[i]][j]);
}
}
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a>>b;
v[a].push_back(b);
grad[b]++;
}
topsort();
for(int i=0;i<g.size();i++){
cout<<g[i]<<'\n';
}
return 0;
}