Pagini recente » Cod sursa (job #1333546) | Cod sursa (job #24997) | Cod sursa (job #2331376) | Cod sursa (job #1520327) | Cod sursa (job #304575)
Cod sursa(job #304575)
#include<stdio.h>
#define nmax 50001
struct tnod{
int x;
tnod*urm;
};
tnod *v[nmax],*ad;
void list(int);
void top();
void add(tnod*&,int);
void df(int);
int n,m,c[nmax];
int main(){
freopen("sortaret.in","r",stdin);
freopen("sortaret.out","w",stdout);
scanf("%d %d",&n,&m);
for(;m>=0;m--){
int x,y;
scanf("%d %d",&x,&y);
add(v[x],y);
}
top();
for(tnod*p=ad;p!=NULL;p=p->urm)
printf("%d ",p->x);
printf("\n");
return 0;
}
void add(tnod*&d,int t){
tnod*p;
p=new tnod;
p->x=t;
p->urm=d;
d=p;
}
void top(){
for(int i=1;i<=n;i++)
if(c[i]==0)
df(i);
}
void df(int t){
c[t]=1;
for(tnod*p=v[t];p!=NULL;p=p->urm)
if(c[p->x]==0)
df(p->x);
c[t]=2;
list(t);
}
void list(int t){
tnod*p;
p=new tnod;
p->x=t;
p->urm=ad;
ad=p;
}