Pagini recente » Cod sursa (job #921472) | Cod sursa (job #933006) | Cod sursa (job #971951) | Cod sursa (job #1405896) | Cod sursa (job #2360624)
#include <fstream>
using namespace std;
ifstream cin("sortaret.in");
ofstream cout("sortaret.out");
struct nod
{
int vf;
nod *next;
} *PNOD, NOD;
nod *L[50005];
nod *adresa;
int v[50005],n,m;
void add(int x, int y)
{
nod *p=new nod;
p->vf=y;
p->next=L[x];
L[x]=p;
}
void citire()
{
int i,j,x,y;
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>x>>y;
add(x,y);
}
}
void push(int x)
{
nod *p=new nod;
p->vf=x;
p->next=adresa;
adresa=p;
}
void df(int i)
{
int j;
v[i]=1;
for(nod *it=L[i];it!=NULL;it=it->next)
{
if(v[it->vf]==0)
df(it->vf);
}
v[i]=2;
push(i);
}
void sortare_top()
{
int i;
for(i=1;i<=m;i++)
{
if(v[i]==0)
df(i);
}
}
void afis()
{
nod *it=new nod;
it=adresa;
while(it)
{
cout<<it->vf<<" ";
it=it->next;
}
}
int main()
{
citire();
sortare_top();
afis();
return 0;
}