Pagini recente » Cod sursa (job #2607329) | Cod sursa (job #342630) | Cod sursa (job #1358465) | Cod sursa (job #1546615) | Cod sursa (job #3225426)
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define pb push_back
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int N = 5e4+3;
int n, m, deg[N];
vector<int> e[N];
int main()
{
fin >> n >> m;
while (m--){
int a, b; fin >> a >> b;
deg[b]++; e[a].pb(b);
}
queue<int> q;
for (int i = 1; i <= n; i++)
if (!deg[i]) q.push(i);
while (!q.empty()){
int nod = q.front(); q.pop();
fout << nod << ' ';
for (auto it: e[nod]){
deg[it]--;
if (!deg[it])
q.push(it);
}
}
return 0;
}
//16:19