我们知道,邻接矩阵自乘t次就是经过t条边的路径数
但这道题显然不能这样,因为不能走回头路
于是我们可以构造边的邻接矩阵矩乘即可
1 const mo=45989; 2 type way=record 3 po,fr:longint; 4 end; 5 node=array[0..122,0..122] of longint; 6 7 var c,a,w:node; 8 ed:array[0..200] of way; 9 x,y,n,m,s,t,e,i,j,ans,len:longint; 10 11 procedure add(x,y:longint); 12 begin 13 inc(len); 14 ed[len].po:=y; 15 ed[len].fr:=x; 16 end; 17 18 procedure mul(var c:node;a,b:node); 19 var i,j,k:longint; 20 begin 21 for i:=1 to len do 22 for j:=1 to len do 23 begin 24 c[i,j]:=0; 25 for k:=1 to len do 26 c[i,j]:=(c[i,j]+a[i,k]*b[k,j]) mod mo; 27 end; 28 end; 29 30 procedure quick(n:longint); 31 begin 32 while n>0 do 33 begin 34 if n mod 2=1 then mul(a,a,w); 35 mul(w,w,w); 36 n:=n shr 1; 37 end; 38 end; 39 40 begin 41 len:=1; 42 readln(n,m,t,s,e); 43 inc(s); 44 inc(e); 45 for i:=1 to m do 46 begin 47 readln(x,y); 48 inc(x); inc(y); 49 add(x,y); 50 add(y,x); 51 end; 52 for i:=2 to len do 53 begin 54 for j:=2 to len do 55 if (i xor 1<>j) then 56 if ed[i].po=ed[j].fr then w[i,j]:=1; 57 a[i,i]:=1; 58 if ed[i].fr=s then c[1,i]:=1; 59 end; 60 quick(t-1); 61 mul(c,c,a); 62 for i:=2 to len do 63 if ed[i].po=e then ans:=(ans+c[1,i]) mod mo; 64 writeln(ans mod mo); 65 end.