Pagini recente » Cod sursa (job #2667244) | Cod sursa (job #2592913) | Cod sursa (job #2883181) | Cod sursa (job #1428327) | Cod sursa (job #1168432)
program euler;
const nmax=100000;
inf=1 shl 30;
type lista=^celula;
celula=record
info:longint;
pred:lista;
end;
var a:array[1..nmax] of lista;
gr:array[1..nmax] of longint;
n,m,x,y,i,j:longint;
r:lista;
ok:boolean;
bufin,bufout:array[1..1 shl 16] of byte;
procedure euler(v:longint;p:longint);
var w:longint;
r:lista;
begin
while a[v]<>nil do
begin
w:=a[v]^.info;
a[v]:=a[v]^.pred;
r:=a[w];
if r^.info=v then a[w]:=a[w]^.pred
else
begin
while r^.pred^.info<>v do r:=r^.pred;
r^.pred:=r^.pred^.pred;
end;
euler(w,p+1);
end;
if p>0 then write(v,' ');
end;
begin
assign(input,'ciclueuler.in');
assign(output,'ciclueuler.out');
settextbuf(input,bufin);
settextbuf(output,bufout);
reset(input);
rewrite(output);
readln(n,m);
for i:=1 to m do
begin
readln(x,y);
inc(gr[x]);
inc(gr[y]);
new(r);
r^.info:=y;
r^.pred:=a[x];
a[x]:=r;
new(r);
r^.info:=x;
r^.pred:=a[y];
a[y]:=r;
end;
ok:=true;
for i:=1 to n do
if gr[i] mod 2=1 then ok:=false;
if not ok then writeln(-1)
else euler(1,0);
close(output);
end.