結果
問題 | No.1750 ラムドスウイルスの感染拡大-hard |
ユーザー |
![]() |
提出日時 | 2021-11-19 21:46:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 212 ms / 2,000 ms |
コード長 | 2,300 bytes |
コンパイル時間 | 2,535 ms |
コンパイル使用メモリ | 221,912 KB |
最終ジャッジ日時 | 2025-01-25 20:13:40 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic popusing namespace std;using namespace atcoder;#define rep(i,n)for (int i = 0; i < int(n); ++i)#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()template<class T> void chmax(T& a, const T& b) { a = max(a, b); }template<class T> void chmin(T& a, const T& b) { a = min(a, b); }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;using mint = modint998244353;template<class R, R (*zero)(), R (*one)()>struct Mat: std::vector<std::vector<R>> {Mat(int n=0): std::vector<std::vector<R>>::vector(n, vector<R>(n, zero())) {}friend Mat operator*(const Mat& lhs, const Mat& rhs) {assert(lhs.size() == rhs.size());const int n = lhs.size();Mat ret(n);for(int i = 0; i < n; i++) for(int k = 0; k < n; k++) for(int j = 0; j < n; j++) {ret[i][j] += lhs[i][k] * rhs[k][j];}return ret;}Mat& operator*=(const Mat& rhs) {return (*this) = (*this) * rhs;}friend Mat operator+(const Mat& lhs, const Mat& rhs) {assert(lhs.size() == rhs.size());const int n = lhs.size();Mat ret(n);for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) ret[i][j] = lhs[i][j] + rhs[i][j];return ret;}Mat& operator+=(const Mat& rhs) {return (*this) = (*this) + rhs;}Mat pow(unsigned long long n) {Mat A = *this;Mat res = Mat::I(A.size());for(; n; n >>= 1) {if (n & 1) res *= A;A *= A;}return res;}static Mat I(int n) {Mat ret(n);for(int i = 0; i < n; i++) ret[i][i] = one();return ret;}};mint zero() { return mint(); }mint one() { return mint::raw(1); }} int main() {ios::sync_with_stdio(false);cin.tie(0);int n, m;ll t;cin >> n >> m >> t;Mat<mint, zero, one> a(n);rep(_, m) {int s, t;cin >> s >> t;a[s][t] = a[t][s] = 1;}cout << a.pow(t)[0][0].val() << '\n';}