洛谷-3758

洛谷-3758

思路

一定要看数据范围!

Code

#include <bits/stdc++.h>
using namespace std;
#define _u_u_ ios::sync_with_stdio(false), cin.tie(nullptr)
#define cf int _o_o_;cin>>_o_o_;for (int Case = 1; Case <= _o_o_;Case++)
#define SZ(x) (int)(x.size())
inline void _A_A_();
signed main() {_A_A_();return 0;}

using ll = long long;
// #define int long long
const int mod = 2017;
const int maxn = 2e5 + 10;
const int N = 210, M = 5010;
const int inf = 0x3f3f3f3f;

int n, m;

struct mat {
    vector<vector<int>> v;
    mat (int n) {
        v.resize(n + 1, vector<int> (n + 1, 0));
    }
};

mat operator * (const mat & a, const mat & b) {
    mat c(n);
    for (int i = 0;i < n + 1;i++) {
        for (int j = 0;j < n + 1;j ++) {
            for (int k = 0;k < n + 1;k ++ ) {
                c.v[i][j] = (c.v[i][j] + a.v[i][k] * b.v[k][j]) % mod;
            }
        }
    }
    return c;
}

mat qpow(mat a, int b) {
    mat c(n);
    for (int i = 0;i < n + 1;i++) {
        c.v[i][i] = 1;
    }
    while (b) {
        if (b & 1) {
            c = c * a;
        }
        a = a * a;
        b >>= 1;
    }
    return c;
}

inline void _A_A_() {
    #ifdef LOCAL
    freopen("in.in", "r", stdin);
    #endif
    _u_u_;
    cin >> n >> m;
    mat s(n);
    for (int i= 0;i < m;i++) {
        int a, b;
        cin >> a >> b;
        s.v[a][b]=1;
        s.v[b][a] = 1;
    }
    int t;
    cin >> t;
    for (int i = 0;i < n + 1;++i) {
        s.v[i][i] =  1;
        s.v[i][0] = 1;
    }
    s = qpow(s, t);
    int ans = 0;
    for (int i = 0;i < n + 1;i++) {
        ans = (ans + s.v[1][i]) % mod;
    }
    cout << ans << "\n";
}
posted @   Uzhia  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示