Pagini recente » Cod sursa (job #643330) | Cod sursa (job #226231) | Cod sursa (job #2397895) | Cod sursa (job #1457619) | Cod sursa (job #2905970)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
vector <int> a[50001];
int nrp[50001], n, m;
int main()
{
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
fin >> n >> m;
for (int i = 0; i < m; i ++)
{
int x, y;
fin >> x >> y;
a[x].push_back(y);
nrp[y]++;
}
queue <int>q;
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);
}
}
fin.close();
fout.close();
return 0;
}