Pagini recente » Cod sursa (job #1159519) | Cod sursa (job #2491284) | Cod sursa (job #161164) | Cod sursa (job #1866566) | Cod sursa (job #210019)
Cod sursa(job #210019)
#include<stdio.h>
FILE *fin=fopen("sortaret.in","r"),
*fout=fopen("sortaret.out","w");
int N, M;
struct nod{int vec;nod* next;};
typedef nod* lista;
lista L[50003];
char conex[50003];
char uz[50003];
void dfs(int p){
fprintf(fout,"%d ",p);
while(L[p]){
dfs(L[p]->vec);
L[p]=L[p]->next;
}
}
int main(){
fscanf(fin,"%d %d",&N,&M);
for(int i=1;i<=N;i++){
L[i]==new nod;
L[i]=NULL;
}
for(int i=1;i<=M;i++){
int x,y;
fscanf(fin,"%d %d",&x,&y);
lista aux;
if(L[x]==NULL){
aux=new nod;
aux->vec=y;
L[x]=aux;
L[x]->next=NULL;
}
else{
aux=L[x];
while(aux->next)
aux=aux->next;
aux->next=new nod;
aux=aux->next;
aux->vec=y;
aux->next=NULL;
}
uz[y]=1;
}
for(int i=1;i<=N;i++)
if(uz[i]==0)
dfs(i);
fclose(fin);
fclose(fout);
return 0;
}