Pagini recente » Istoria paginii utilizator/cretuirina | Diferente pentru home intre reviziile 452 si 453 | Diferente pentru preoni-2007/runda-3/solutii intre reviziile 1 si 53 | Cod sursa (job #2194964) | Cod sursa (job #240131)
Cod sursa(job #240131)
program alex;
var f:text;
a:array[1..4,1..1000]of integer;
st: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;
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 for h:=1 to j-1 do
if st[j]=st[h] then begin
ev:=false;
break;
end;
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 j:=j-1;
end;
close(f);
end.