标签:des style blog http color os io 数据
对于30%的数据,N ≤ 4,M ≤ 10,t ≤ 10。
对于100%的数据,N ≤ 20,M ≤ 60,t ≤ 230,0 ≤ A,B<n,0 ≤="" ai,bi="" <n。<="" p="">
1 const p=45989; 2 type matrix=array[0..200,0..200] of int64; 3 var a,b:matrix; 4 c:array[0..1000] of record x,y:longint;end; 5 i,j,n,m,x,y,s,t,dist,ans,mm:longint; 6 procedure init; 7 begin 8 readln(n,m,dist,s,t);mm:=m<<1-1; 9 for i:=0 to m-1 do 10 begin 11 readln(x,y); 12 c[i<<1].x:=x;c[i<<1].y:=y; 13 c[i<<1+1].x:=y;c[i<<1+1].y:=x; 14 end; 15 end; 16 procedure mul(var x,y,z:matrix); 17 var t:matrix;i,j,k:longint; 18 begin 19 fillchar(t,sizeof(t),0); 20 for i:=0 to mm do 21 for j:=0 to mm do 22 for k:=0 to mm do 23 t[i,j]:=(t[i,j]+x[i,k]*y[k,j]) mod p; 24 z:=t; 25 end; 26 27 procedure ksm(cs:longint); 28 begin 29 while cs>0 do 30 begin 31 if cs and 1=1 then mul(a,b,b); 32 cs:=cs>>1; 33 mul(a,a,a); 34 end; 35 end; 36 37 procedure main; 38 begin 39 fillchar(a,sizeof(a),0); 40 for i:=0 to mm do 41 for j:=0 to mm do 42 if (i<>j) and (i xor 1<>j) and (c[i].y=c[j].x) then 43 inc(a[i,j]); 44 for i:=0 to mm do b[i,i]:=1; 45 ksm(dist-1); 46 ans:=0; 47 for i:=0 to mm do 48 for j:=0 to mm do 49 if (c[i].x=s) and (c[j].y=t) then ans:=(ans+b[i,j]) mod p; 50 writeln(ans); 51 end; 52 53 begin 54 assign(input,‘input.txt‘);assign(output,‘output.txt‘); 55 reset(input);rewrite(output); 56 init; 57 main; 58 close(input);close(output); 59 end.
BZOJ1875: [SDOI2009]HH去散步,布布扣,bubuko.com
标签:des style blog http color os io 数据
原文地址:http://www.cnblogs.com/zyfzyf/p/3902405.html