Pagini recente » Cod sursa (job #776929) | Cod sursa (job #2683714) | Cod sursa (job #634544) | Cod sursa (job #1365846) | Cod sursa (job #2179078)
#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[5000];
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;
}