Pagini recente » Cod sursa (job #2230807) | Cod sursa (job #1337240) | Cod sursa (job #2044273) | Cod sursa (job #135362) | Cod sursa (job #2179075)
#include <bits/stdc++.h>
using namespace std;
int i,j,m,n,x,y,a,b;
struct tab
{
queue<int> l;
int nr;
};
tab t[50005];
queue <int> nod;
int main()
{
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
fin>>n>>m;
for (i=1;i<=m;i++)
{
fin>>a>>b;
t[a].l.push(b);
t[b].nr++;
}
for (i=1;i<=n;i++)
if (t[i].nr==0) nod.push(i);
while (!nod.empty())
{
x=nod.front();
fout<<x<<" ";
while (!t[x].l.empty())
{
t[t[x].l.front()].nr--;
if (t[t[x].l.front()].nr==0) nod.push(t[x].l.front());
t[x].l.pop();
}
nod.pop();
}
return 0;
}