Pagini recente » Cod sursa (job #652508) | Cod sursa (job #2887646) | Cod sursa (job #2967294) | Cod sursa (job #2690481) | Cod sursa (job #2720989)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int nrp[100005];
vector<int>s[100005];
queue<int>q;
int main()
{
int m, n;
fin>>n>>m;
for(int i = 0; i < m; i++)
{
int x, y;
fin>>x>>y;
s[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:s[x])
{
nrp[y]--;
if(nrp[y] == 0)
{
q.push(y);
}
}
}
return 0;
}