Pagini recente » Cod sursa (job #3287391) | Cod sursa (job #775989) | Cod sursa (job #2622646) | Cod sursa (job #433103) | Cod sursa (job #1481860)
#include<stdio.h>
int edges[100001],next[100001],last[50001],first[50001],viz[50001],coada[50001],nr;
typedef struct nod {
int vf;
nod * next;
} *PNOD, NOD;
PNOD adresa;
void push(int nod)
{
PNOD p = new NOD;
p->vf = nod;
p->next = adresa;
adresa = p;
}
void dfs(int nod){
int p=first[nod];
//printf("%d",nod);
viz[nod]=1;
while(p!=0){
if(viz[edges[p]]==0)
dfs(edges[p]);
p=next[p];
}
push(nod);
}
int main(){
// freopen("sortaret.in","r",stdin);
// freopen("sortaret.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
int i,cont=1;
for(i=0;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
if(first[x]==0){
first[x]=cont;
last[x]=cont;
}
else{
next[last[x]]=cont;
last[x]=cont;
}
edges[cont++]=y;
}
for(i=1;i<=n;i++)
if(viz[i]==0)
dfs(i);
for ( PNOD p = adresa; p; p = p->next )
printf( "%d ", p->vf );
return 0;
}