Pagini recente » Cod sursa (job #1505965) | Cod sursa (job #1495966) | Cod sursa (job #3268906) | Cod sursa (job #2983019) | Cod sursa (job #2968464)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("sortareset.in");
ofstream fout("sortareset.out");
typedef long long ll;
const ll NMAX=5e4+5;
vector<ll> edg[NMAX];
ll deg[NMAX];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,m;
fin>>n>>m;
for(ll i=0;i<m;i++){
ll u,v;
fin>>u>>v;
edg[u].push_back(v);
++deg[v];
}
queue<ll> q;
for(ll i=1;i<=n;i++){
if(deg[i]==0)
q.push(i);
}
while(!q.empty()){
fout<<q.front()<<' ';
for(auto it : edg[q.front()]){
--deg[it];
if(deg[it]==0) q.push(it);
}
q.pop();
}
return 0;
}