Pagini recente » Cod sursa (job #1537058) | Cod sursa (job #3155090) | Cod sursa (job #533747) | Cod sursa (job #3239384) | Cod sursa (job #222655)
Cod sursa(job #222655)
#include <iostream>
#include<stdio.h>
using namespace std;
#define maxn 50100
int m,n;
typedef struct nod{
int vf;
nod *urm;
}*PNOD,NOD;
PNOD L[maxn];
PNOD adresa;
int color[maxn];
void Push( int nod )
{
PNOD p = new NOD;
p->vf = nod;
p->urm = p;
}
void df(int nod)
{
color[nod]=1;
for ( PNOD p = L[nod]; p; p = p->urm )
if ( color[p->vf] == 0 )
df( p->vf );
color[nod] = 2;
Push( nod );
}
void s_top()
{int i;
for(i=1;i<=n;++i)
if(color[i]=0)
df(i);
}
void add(int i,int j)
{PNOD p;
p->vf=j;
p->urm=L[i];
L[i]=p;
}
void read()
{freopen("sortaret.in","r",stdin);
scanf("%d %d\n",&n,&m);
int x,y;
for(;m>0;m--)
{scanf("%d %d",&x,&y);
add(x,y);
}
}
void write()
{freopen("sortaret.out","w",stdout);
for(PNOD p=adresa;p;p=p->urm)
printf("%d ",p->vf);
}
int main()
{read();
s_top();
write();
return 0;
}