Cod sursa(job #772703)
Program ciclueuler;
type lista=^celula;
celula=record
nod,pos:longint;
next:lista;
end;
var g:array [1..100001] of lista;
much:array [1..500001] of boolean;
b:array [1..100001] of longint;
v:lista;
b1,b2:array [1..1 shl 17] of char;
ok:boolean;
i,n,m,x,y:longint;
fi,fo:text;
procedure dfs(nod:longint);
var p:lista;
begin
p:=g[nod];
while p<>nil do begin
if much[p^.pos]=false then begin much[p^.pos]:=true; dfs(p^.nod); write(fo,nod,' '); end;
p:=p^.next;
end;
end;
begin
assign(fi,'ciclueuler.in');
assign(fo,'ciclueuler.out');
settextbuf(fi,b1); settextbuf(fo,b2);
reset(fi); rewrite(fo); readln(fi,n,m);
for i:=1 to m do begin
readln(fi,x,y); inc(b[x]); inc(b[y]);
new(v); v^.nod:=y; v^.pos:=i; v^.next:=g[x]; g[x]:=v;
new(v); v^.nod:=x; v^.pos:=i; v^.next:=g[y]; g[y]:=v;
end;
for i:=1 to n do if b[i] mod 2=1 then ok:=true;
if ok then write(fo,'-1') else dfs(1);
close(fo);
end.