Pagini recente » Cod sursa (job #1340095) | Cod sursa (job #1546704) | Cod sursa (job #1805685) | Cod sursa (job #1860675) | Cod sursa (job #841870)
Cod sursa(job #841870)
program sortaretopologica;
type lista=^celula;
celula=record
info:longint;
next:lista;
end;
var f:text;
p,v,r,q:lista;
n,m,i,x,y:longint;
a:array [1..50000] of byte;
begin
assign(f,'sortaret.in');
reset(f);
readln(f,n,m);
readln(f,x,y);
new(p);
p^.info:=x;
new(v);
p^.next:=v;
v^.info:=y;
v^.next:=nil;
a[x]:=1;a[y]:=1;
for i:=2 to m do
begin
readln(f,x,y);
if a[x]=1 then
begin
new(q);
q^.info:=y;
q^.next:=nil;
v^.next:=q;
v:=q;a[y]:=1;
end
else
begin
new(q);
q^.info:=x;
q^.next:=nil;
v^.next:=q;
v:=q;
new(q);
q^.info:=y;
q^.next:=nil;
v^.next:=q;
v:=q; a[x]:=1;a[y]:=1;
end;
end;
close(f);
assign(f,'sortaret.out');
rewrite(f);
r:=p;
while r<>nil do
begin
write(f,r^.info,' ');
r:=r^.next;
end;
close(f);
end.