Pagini recente » Cod sursa (job #681362) | Cod sursa (job #530503) | Cod sursa (job #2527809) | Cod sursa (job #3189662) | Cod sursa (job #2179094)
#include <bits/stdc++.h>
using namespace std;
int i,j,m,n,x,y,a,b;
struct tab
{
vector<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_back(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.back()].nr--;
if (t[t[x].l.back()].nr==0) nod.push(t[x].l.back());
t[x].l.pop_back();
}
nod.pop();
}
return 0;
}