Pagini recente » Cod sursa (job #2050958) | Cod sursa (job #2505783) | Cod sursa (job #487644) | Cod sursa (job #3171512) | Cod sursa (job #117374)
Cod sursa(job #117374)
Program dusman;
Var f,ff:text;
n,kp,m,pp,fl,l,aa,bb,t,tt:int64;
i,j,k,k1:longint;
p:array[0..1006] of longint;
a:array[0..1005,0..1005] of longint;
Begin
assign(f,'dusman.in');
reset(f);
assign(ff,'dusman.out');
rewrite(ff);
readln(f,n,kp,m);
for i:=1 to m do begin readln(f,aa,bb); a[aa,bb]:=1; a[bb,aa]:=1; end;
for i:=2 to n do p[i]:=i;
p[1]:=1;
fl:=1;
for j:=1 to n-1 do
if a[p[j],p[j+1]]=1 then
begin
tt:=p[j+1];
t:=0;
i:=j+1;
repeat
inc(i);
t:=p[i];
p[i]:=tt;
tt:=t;
until(a[p[j],tt]=0);
p[j+1]:=tt;
end;
if fl=1 then inc(l);
if (fl=1)and(kp=l) then
begin
for j:=1 to n do Write(ff,p[j],' ');
Writeln(ff);
close(f);
close(ff);
halt;
end;
repeat
for k:=n-1 downto 1 do if p[k]<p[k+1] then break;
for k1:=n downto 1 do if p[k1]>p[k] then break;
pp:=p[k];
p[k]:=p[k1];
p[k1]:=pp;
for j:=k+1 to (n+k+1) div 2 do
begin
pp:=p[j];
p[j]:=p[n-(j-k)+1];
p[n-(j-k)+1]:=pp;
end;
fl:=1;
for j:=1 to n-1 do
if a[p[j],p[j+1]]=1 then
begin
fl:=0;
break;
end;
if fl=1 then inc(l);
if (fl=1)and(kp=l) then
begin
for j:=1 to n do Write(ff,p[j],' ');
Writeln(ff);
close(f);
close(ff);
halt;
end;
until(1>2);
End.