Pagini recente » Cod sursa (job #1654796) | Cod sursa (job #2888668) | Cod sursa (job #616256) | Cod sursa (job #616439) | Cod sursa (job #2718927)
#include <fstream>
#include <vector>
#include <queue>
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
using namespace std;
const int N = 50001;
vector <int> a[N];
queue <int> q;
int n, m, nrp[N];
int main()
{
fin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
fin >> x >> y;
a[x].push_back(y);
nrp[y]++;
}
for (int i = 1; i <= n; i++)
{
if (nrp[i] == 0)
{
q.push(i);
}
}
while (!q.empty())
{
int x = q.front();
fout << x << " ";
q.pop();
for (auto y : a[x])
{
nrp[y]--;
if (nrp[y] == 0)
{
q.push(y);
}
}
}
return 0;
}