Pagini recente » Cod sursa (job #708946) | Cod sursa (job #2003513) | Profil Matei_CNSH01 | Cod sursa (job #426521) | Cod sursa (job #164429)
Cod sursa(job #164429)
program sort_top;
type point=^lista;
lista=record
inf:longint;
leg:point;
end;
var l:array[0..50005] of point;
c:array[0..50005] of longint;
sel:array[0..50005] of boolean;
i,n,x,y,m:longint;
p:point;
f,g:text;
procedure df(nod:longint);
var p:point;
begin
sel[nod]:=true;
p:=l[nod];
while p<>nil do begin
if sel[p^.inf]=false then df(p^.inf);
p:=p^.leg;
end;
inc(c[0]); c[c[0]]:=nod;
end;
begin
assign(f,'sortaret.in'); reset(f);
assign(g,'sortaret.out'); rewrite(g);
readln(f,n,m);
for i:=1 to n do l[i]:=nil;
for i:=1 to m do begin
readln(f,x,y);
new(p); p^.inf:=y; p^.leg:=l[x]; l[x]:=p;
end;
fillchar(sel, sizeof(sel),0);
df(1);
for i:=n downto 2 do write(g,c[i],' ');
writeln(g,c[1]);
close(g); close(f);
end.