analysis
I always felt when the examination questions and then you saw them ...... like a good approach is to think of it after the matrix multiplication exercises of J Lord
We can find moments multiplication process is actually a process similar to floyd, you can put the path one point to another point total grows out, so is the number of programs in the case of the edge weights of 1
Then a look at the big K can probably guess that moment take, but do not cry food fight
Because the fish are circulating section, we can put the least common multiple cycle power section as a quick reference
A first matrix T from a process where 1 to 12 all the time are multiplied together
Then quickly power ^ k / 12
Finally, multiply-by-k matrix T to 12%
#include <iostream> #include <cstdio> #include <memory.h> using namespace std; typedef long long ll; const int N=60; const ll P=1e4; int n,fish,m,st,ed,K,fp[N][N]; bool use[N]; struct Rect { ll a[N][N]; ll *operator [](int i){return a[i];} void In() { for (int i=0;i<n;i++) a[i][i]=1; } void Empty() {memset(a,0,sizeof a);} Rect operator * (Rect b) { Rect c;c.Empty(); for (int i=0;i<n;i++) for (int j=0;j<n;j++) for (int k=0;k<n;k++) if (!use[k]) (c[i][j]+=a[i][k]*b[k][j]%P)%=P; return c; } } F years, e; Rect Ksm(Rect a,int y) { Rect years; memset(use,0,sizeof use);ans.In(); while (y) { if (y&1) ans=ans*a; a=a*a; y>>=1; } return years; } void Pre_Process(int x) { memset(use,0,sizeof use); for (int i=1;i<=fish;i++) use[fp[i][(x-1)%fp[i][0]+1]]=1; } int main () { scanf("%d%d%d%d%d",&n,&m,&st,&ed,&K);e.In();ans.In(); for (int i=1,u,v;i<=m;i++) scanf("%d%d",&u,&v),f[u][v]++,f[v][u]++; scanf("%d",&fish); for (int i=1;i<=fish;i++) { scanf("%d",&fp[i][0]); for (int j=1;j<=fp[i][0];j++) scanf("%d",&fp[i][j]); } for (int i=1;i<=12;i++) Pre_Process(i),e=e*f; ans=ans*Ksm(e,K/12); for (int i=1;i<=K%12;i++) Pre_Process (i) years = years * f; printf("%lld",ans.a[st][ed]); }