Pagini recente » Cod sursa (job #2709418) | Cod sursa (job #2709414) | Cod sursa (job #2389273) | Cod sursa (job #2448305)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m,grad[50001],x,y;
vector<int>lista[50001];
queue<int>coada;
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
fin>>x>>y;
grad[y]++;
lista[x].push_back(y);
}
for(int i=1;i<=n;i++)
if(grad[i]==0)
coada.push(i);
while(!coada.empty())
{
int nod=coada.front();
coada.pop();
fout<<nod<<" ";
for(int i=0;i<lista[nod].size();i++)
{
grad[lista[nod][i]]--;
if(grad[lista[nod][i]]==0)
coada.push(lista[nod][i]);
}
}
return 0;
}