比赛 2024暑假C班集训D 评测结果 AAAAAAAAAA
题目名称 沼泽鳄鱼 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.192 s
代码语言 C++ 内存使用 4.00 MiB
提交时间 2024-07-13 09:18:15
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
const int N = 60,M = 2e3+10;
const ll mod = 10000;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}

int n,m,nf,st,en;
ll k;
struct made{
    int ver,nx;
}e[M<<1];
int hd[N],tot;
void link(int x,int y){e[++tot] = {y,hd[x]},hd[x] = tot;}


struct Matrix{
    ll a[N][N];int n,m;
    void clear(){n = m = 0;memset(a,0,sizeof a);}
    Matrix operator * (const Matrix x)const{
        Matrix y;y.clear();
        y.n = n,y.m = m;
        for(int i = 1;i <= n;i++)
            for(int j = 1;j <= m;j++)
                for(int k = 1;k <= m;k++)y.a[i][j] = (y.a[i][j] + a[i][k] * x.a[k][j] % mod) % mod;
        return y;
    }
}F,U[14];

ll f[N][M];
int t[N][7],l[N];
int main(){
    freopen("swamp.in","r",stdin);
    freopen("swamp.out","w",stdout);
    n = read(),m = read(),st = read() + 1,en = read() + 1,k = read();
    for(int i = 1;i <= m;i++){
        int x = read() + 1,y = read() + 1;
        link(x,y),link(y,x);
    }
    nf = read();
    for(int i = 1;i <= nf;i++){
        l[i] = read();
        for(int j = 0;j < l[i];j++)t[i][j] = read() + 1;
    }
    for(int T = 1;T <= min(12ll,k);T++){
        U[T].n = U[T].m = n;
        for(int x = 1;x <= n;x++){
            bool fl = 1;
            for(int j = 1;j <= nf;j++)
                    if(x == t[j][T % l[j]]){fl = 0;break;}
            if(!fl)continue;
            for(int i = hd[x];i;i = e[i].nx){
                int y = e[i].ver;
                U[T].a[y][x] += 1;
            }
        }
        if(T != 1)U[T] = U[T-1] * U[T];
    }
    ll x = k / 12ll;k %= 12;
    F.n = 1,F.m = n,F.a[1][st] = 1;
    while(x){
        if(x & 1)F = F * U[12];
        U[12] = U[12] * U[12];
        x >>= 1; 
    }
    if(k)F = F * U[k];
    printf("%lld\n",F.a[1][en]);
    
    
    return cerr<<clock()<<"ms"<<endl,0;
    
}