Cod sursa(job #252180)

Utilizator MihaiBunBunget Mihai MihaiBun Data 3 februarie 2009 23:06:50
Problema Lista lui Andrei Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.81 kb
PROGRAM lista;
var f:text;
begin
  assign(f,'nrcuv.in');
  reset(f);
  readln(f,n,m);
  for i:=1 to m do
    begin
       readln(f,a,b);
       mat[a,b]:=1;
       mat[b,a]:=1;
    end;
  j:=1;
  st[j]:=pred('a');
  while j>0 do
  begin
    repeat
      if st[j]<'z' then begin
                           st[j]:=succ[st[j]);
                           as:=true
                        end
                   else as:=false;
      if as then if mat[st[j],st[j-1]]=1 then ev:=false
                                         else ev:=true
    until (not as) or (as and ev);
    if as then if j=n then nr:=(nr+1)mod 104659
                      else begin
                            j:=j+1;
                            st[j]:=pred('a')
                           end
          else j:=j-1
  end;


end.