Pagini recente » Cod sursa (job #1754787) | Cod sursa (job #2472045) | Profil bananamandaone | Cod sursa (job #3139920) | Cod sursa (job #2172606)
#include <bits/stdc++.h>
using namespace std;
ifstream F("sortaret.in");
ofstream G("sortaret.out");
int n, m, x, y, deg[50005];
queue<int> q, sol;
vector<int>a[50005];
int main()
{
F>>n >> m;
for(int i = 1; i <= m; ++ i){
F >>x>> y;
a[x].push_back(y);
deg[y]++;
}
for(int i = 1; i <= n; ++ i)
if(!deg[i]) q.push(i);
while(!q.empty()){
x=q.front();
q.pop();
sol.push(x);
for(auto it:a[x]){
deg[it]--;
if(!deg[it])q.push(it);
}
}
while(!sol.empty()){
G << sol.front()<< " ";
sol.pop();
}
return 0;
}