Pagini recente » Cod sursa (job #1476878) | Cod sursa (job #59823) | Cod sursa (job #126394) | Cod sursa (job #466657) | Cod sursa (job #3227116)
#include <bits/stdc++.h>
using namespace std;
vector <int> L[100001];
int indeg[100001];
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int main()
{
int n, m;
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
fin >> x >> y;
L[x].push_back(y);
indeg[y]++;
}
priority_queue <int, vector<int>, greater<int>> q;
for (int i = 1; i <= n; i++)
if (indeg[i] == 0)
q.push(i);
while (!q.empty())
{
int curr = q.top();
cout << curr << " ";
q.pop();
for (auto next : L[curr])
{
indeg[next]--;
if (indeg[next] == 0)
q.push(next);
}
}
return 0;
}