Pagini recente » Cod sursa (job #124898) | Cod sursa (job #2425358) | Cod sursa (job #2914844) | Cod sursa (job #172927) | Cod sursa (job #1168431)
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;
procedure euler(v: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);
end;
write(v,' ');
end;
begin
assign(input,'ciclueuler.in');
assign(output,'ciclueuler.out');
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);
close(output);
end.