結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー |
|
提出日時 | 2022-07-25 23:23:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 213 ms / 2,000 ms |
コード長 | 1,513 bytes |
コンパイル時間 | 5,153 ms |
コンパイル使用メモリ | 257,360 KB |
最終ジャッジ日時 | 2025-01-30 14:09:01 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair<int, int> #define LP pair<ll, ll> #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() template<class T> void chmax(T& a, T b) { a = max(a, b); }; template<class T> void chmin(T& a, T b) { a = min(a, b); }; using mint = modint998244353; template<typename T> struct Matrix { int h, w; vector<vector<T>> d; Matrix() {} Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector<T>(w,val)) {} Matrix& unit() { assert(h == w); rep(i,h) d[i][i] = 1; return *this; } const vector<T>& operator[](int i) const { return d[i];} vector<T>& operator[](int i) { return d[i];} Matrix operator*(const Matrix& a) const { assert(w == a.h); Matrix r(h, a.w); rep(i,h)rep(k,w)rep(j,a.w) { r[i][j] += d[i][k]*a[k][j]; } return r; } Matrix pow(ll t) const { assert(h == w); if (!t) return Matrix(h,h).unit(); if (t == 1) return *this; Matrix r = pow(t>>1); r = r*r; if (t&1) r = r*(*this); return r; } }; int main() { int n, m; ll t; cin >> n >> m >> t; Matrix<mint> d(n,n), x(n,1); x[0][0] = 1; rep(i,m) { int a, b; cin >> a >> b; d[a][b] = 1; d[b][a] = 1; } auto ans = d.pow(t)*x; cout << ans[0][0].val() << endl; return 0; }