Cod sursa(job #273467)

Utilizator FllorynMitu Florin Danut Flloryn Data 8 martie 2009 17:07:04
Problema Sortare topologica Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.59 kb
program pascal;
var f,g:text;   a:array[1..30000,1..25000] of byte;
                i,j,x,y,n,m,k:longint; s:array[0..50000] of byte;

 procedure citire;
 begin
 assign(f,'sortaret.in'); reset(f);
 assign(g,'sortaret.out'); rewrite(g);
 readln(f,n,m);
 k:=0;
 for i:=1 to m do
    begin
    readln(f,x,y);
    a[x,y]:=1; a[y,x]:=1;
    end;
 end;

 procedure df(nod:longint);
 var j:longint;
 begin
 write(g,nod,' ');
 s[nod]:=1;
 for j:=1 to n do
 if (s[j]=0) and (a[nod,j]=1) then df(j);
 end;

begin
citire;
for i:=1 to n do
if s[i]=0 then df(i);
close(f);
close(g);
end.