結果
| 問題 |
No.1750 ラムドスウイルスの感染拡大-hard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-31 02:33:27 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 275 ms / 2,000 ms |
| コード長 | 2,517 bytes |
| コンパイル時間 | 3,498 ms |
| コンパイル使用メモリ | 260,476 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-31 02:33:35 |
| 合計ジャッジ時間 | 7,570 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
template<typename T> struct Matrix : vector<vector<T>> {
using vector<vector<T>>::vector;
using vector<vector<T>>::operator=;
Matrix() {}
Matrix(ll n) {
this->assign(n, vector<T>(n, 0));
for(ll i = 0; i < n; i++) { (*this)[i][i] = 1; }
}
Matrix(ll n, ll m, T x = 0) {
for(ll i = 0; i < n; i++) { this->push_back(vector<T>(m, x)); }
}
Matrix(vector<vector<T>> v) { *this = v; }
Matrix operator+(const Matrix &m) const { return Matrix(*this) += m; }
Matrix operator-(const Matrix &m) const { return Matrix(*this) -= m; }
Matrix operator*(const Matrix &m) const { return Matrix(*this) *= m; }
Matrix operator*(const T &x) const { return Matrix(*this) *= x; }
Matrix operator^(ll n) const { return Matrix(*this) ^= n; }
Matrix operator+=(const Matrix &m) const {
ll h = this->size(), w = (*this)[0].size();
assert(h == m.size() && w == m[0].size());
for(ll i = 0; i < h; i++) {
for(ll j = 0; j < w; j++) { *this[i][j] += m[i][j]; }
}
return *this;
}
Matrix operator-=(const Matrix &m) {
ll h = this->size(), w = (*this)[0].size();
assert(h == m.size() && w == m[0].size());
for(ll i = 0; i < h; i++) {
for(ll j = 0; j < w; j++) { *this[i][j] -= m[i][j]; }
}
return *this;
}
Matrix operator*=(const Matrix &m) {
ll h = this->size(), w = (*this)[0].size();
assert(w == (ll)m.size());
vector<vector<T>> r(h, vector<T>(m[0].size(), T(0)));
for(ll i = 0; i < h; i++) {
for(ll j = 0; j < (ll)m[0].size(); j++) {
for(ll k = 0; k < w; k++) { r[i][j] += (*this)[i][k] * m[k][j]; }
}
}
this->swap(r);
return *this;
}
Matrix operator*=(const T &x) {
ll h = this->size(), w = (*this)[0].size();
for(ll i = 0; i < h; i++) {
for(ll j = 0; j < w; j++) { *this[i][j] *= x; }
}
return *this;
}
Matrix operator^=(ll n) {
ll h = this->size();
Matrix m(h);
while(n) {
if(n & 1) { m *= *this; }
*this *= *this;
n >>= 1LL;
}
this->swap(m);
return *this;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, M, T;
cin >> N >> M >> T;
Matrix<mint> dp(N, 1), mul(N, N);
dp[0][0] = 1;
for(ll i = 0; i < M; i++) {
ll a, b;
cin >> a >> b;
mul[a][b] = mul[b][a] = 1;
}
dp = (mul ^ T) * dp;
cout << dp[0][0].val() << "\n";
}