Pagini recente » Cod sursa (job #1354090) | Cod sursa (job #3040864) | Cod sursa (job #1690936) | Cod sursa (job #1460007) | Cod sursa (job #252197)
Cod sursa(job #252197)
program lista;
var f:text;
as,ev:boolean;
st:array[1..1000] of 0..26;
mat:array[1..26,1..26] of 0..1;
n,m,i,j:integer;
nr:longint;
a,b,c:char;
begin
assign(f,'nrcuv.in');
reset(f);
readln(f,n,m);
for i:=1 to m do
begin
read(f,a);read(f,c);readln(f,b);
if mat[ord(a)-96,ord(b)-96]=0 then
begin
mat[ord(a)-96,ord(b)-96]:=1;
mat[ord(b)-96,ord(a)-96]:=1;
end;
end;
close(f);
assign(f,'nrcuv.out');
rewrite(f);
nr:=0;
j:=1;
st[j]:=0;
while j>0 do
begin
repeat
if st[j]<26 then begin
st[j]:=st[j]+1;
as:=true
end
else as:=false;
if as then if j>1 then if mat[st[j],st[j-1]]=1 then ev:=false
else ev:=true
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]:=0
end
else j:=j-1
end;
writeln(f,nr);
close(f);
end.