Pagini recente » Cod sursa (job #3212094) | Cod sursa (job #2139687) | Cod sursa (job #3165474) | Cod sursa (job #3166778) | Cod sursa (job #2786839)
#include <bits/stdc++.h>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
const int N=5e4+1;
int n,m,nrp[N];
vector <int> a[N];
queue <int> q;
int main() {
f>>n>>m;
for(int i=1; i<=m; i++){
int x,y;
f>>x>>y;
a[x].push_back(y);
nrp[y]++;
}
for(int i=1; i<=n; i++)
if(!nrp[i])
q.push(i);
while(!q.empty()){
int x=q.front();
g<<x<<" ";
q.pop();
for(auto j:a[x]){
nrp[j]--;
if(!nrp[j])
q.push(j);
}
}
return 0;
}