洛谷-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";
}
标签:3758,洛谷,mat,int,cin,++,ans
From: https://www.cnblogs.com/FanWQ/p/16903758.html