Pagini recente » Cod sursa (job #2702768) | Cod sursa (job #3120656) | Cod sursa (job #1845629) | Cod sursa (job #1151756) | Cod sursa (job #240195)
Cod sursa(job #240195)
program alex;
var f:text;
a:array[1..4,1..1000]of integer;
st,v:array[1..1000]of integer;
i,m,l,j,h,n,k,x,y,d,c:longint;
e,ev,as:boolean;
begin
assign(f,'dusman.in');reset(f);
readln(f,n,k,m);
for i:=1 to m do
begin
read(f,x,y);
a[4,x]:=a[4,x]+1;
l:=a[4,x];
a[l,x]:=y;
a[4,y]:=a[4,y]+1;
l:=a[4,y];
a[l,y]:=x;
end;
close(f);
j:=1;
st[j]:=0;
e:=false;
d:=0;
assign(f,'dusman.out');rewrite(f);
while not e do
begin
repeat
if st[j]<n then begin
st[j]:=st[j]+1;
v[st[j]]:=1;
as:=true;
end
else as:=false;
if as then begin
c:=st[j];
ev:=true;
if j>1 then begin
for h:=1 to a[4,c] do
if a[h,c]=st[j-1] then ev:=false;
if ev then if v[st[j]]=1 then ev:=false;
end;
end;
until(not as)or(as and ev);
if as then if j=n then begin
d:=d+1;
if d=k then begin for h:=1 to j do
write(f,st[h],' ');
e:=true;
end;
end
else begin
j:=j+1;
st[j]:=0;
end
else begin
v[st[j]]:=0;
j:=j-1;
end;
end;
close(f);
end.