Pagini recente » Cod sursa (job #235885) | Cod sursa (job #469884) | Cod sursa (job #2519050) | Cod sursa (job #2939508) | Cod sursa (job #578989)
Cod sursa(job #578989)
type muchie = ^nod;
nod = record n:longint; a:muchie; end;
var v:array [0..100000] of muchie;
par:array [1..100000] of longint;
sol, temp:array[-1..600000] of longint;
m, n, i, x, y, vf, t, c:longint;
p, r, q, qq:muchie;
f, g:text;
k:boolean;
buf1, buf2:array[1.. 1 shl 17] of char;
begin
assign (f, 'ciclueuler.in'); settextbuf (f, buf1); reset (f);
assign (g, 'ciclueuler.out'); settextbuf (g, buf2); rewrite (g);
readln (f, n, m);
for i := 1 to m do
begin
readln (f, x, y);
if v[x]= nil then
begin
new(v[x]); v[x]^.a:=nil; v[x]^.n:=y;
end
else
begin
p:=v[x];
while p^.a <> nil do p:=p^.a;
new(r); p^.a:=r; r^.a:=nil; r^.n:=y;
end;
if v[y]= nil then
begin
new(v[y]); v[y]^.a:=nil; v[y]^.n:=x;
end
else
begin
p:=v[y];
while p^.a <> nil do p:=p^.a;
new(r); p^.a:=r; r^.a:=nil; r^.n:=x;
end;
inc(par[x]); inc(par[y]);
end;
c:=1;
for i := 1 to n do
begin
if par[i] mod 2 = 1 then c:=-1;
end;
i:=0;
if c=-1 then writeln (g, c)
else
begin
p:=v[c]; qq:=p;
vf:=1; t:=0;
while vf>0 do
begin
if p <> nil then
begin
temp[vf]:=p^.n;
inc (vf);
if p = qq then v[c]:=v[c]^.a
else qq^.a:=p^.a;
q:=v[p^.n]; qq:=q;
q:=v[p^.n]; qq:=q;
k:= true;
while k and (q<> nil) do
begin
if q^.n=c then
begin
k := false;
if qq=q then v[p^.n]:=v[p^.n]^.a
else qq^.a:=q^.a;
end;
q:=q^.a; if qq^.a <> q then qq:=qq^.a;
end;
c:=p^.n;
p:=v[p^.n]; qq:=p;
end
else
begin
inc (t);
dec(vf);
sol[t]:= temp[vf];
p:=v[temp[vf-1]]; qq:=p;
c:=temp[vf-1];
end;
end;
end;
for i := 1 to t-1 do write (g, sol[i], ' ');
close (f); close (g);
end.