Cod sursa(job #240195)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 6 ianuarie 2009 23:02:57
Problema Dusman Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.74 kb
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.