結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー maguroflymagurofly
提出日時 2021-11-19 22:09:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 1,965 bytes
コンパイル時間 5,925 ms
コンパイル使用メモリ 204,616 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 08:42:36
合計ジャッジ時間 6,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 47 ms
4,376 KB
testcase_09 AC 47 ms
4,380 KB
testcase_10 AC 47 ms
4,376 KB
testcase_11 AC 36 ms
4,380 KB
testcase_12 AC 51 ms
4,380 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 245 ms
4,376 KB
testcase_15 AC 249 ms
4,380 KB
testcase_16 AC 250 ms
4,380 KB
testcase_17 AC 254 ms
4,380 KB
testcase_18 AC 262 ms
4,380 KB
testcase_19 AC 253 ms
4,380 KB
testcase_20 AC 174 ms
4,380 KB
testcase_21 AC 199 ms
4,380 KB
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 240 ms
4,380 KB
testcase_24 AC 28 ms
4,380 KB
testcase_25 AC 65 ms
4,380 KB
testcase_26 AC 22 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 35 ms
4,376 KB
testcase_31 AC 33 ms
4,380 KB
testcase_32 AC 32 ms
4,380 KB
testcase_33 AC 32 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, l, r) for (auto i = (l); i < (r); i++)
#define all(a) a.begin(), a.end()
#define chmin(dest, src) if ((dest) > (src)) dest = (src)
#define chmax(dest, src) if ((dest) < (src)) dest = (src)
using ll = long long;
using i64 = long long;
using i32 = long;
using u64 = unsigned long long;
using u32 = unsigned long;

const ll MOD = 998244353;

using Type = ll;
using Matrix = vector<vector<ll>>;
Matrix Mul(const Matrix &a, const Matrix &b) {
        assert(a[0].size() == b.size());
        Matrix c(a.size(), vector<Type> (b[0].size(), 0));
        for (int i = 0; i < a.size(); i ++) {
                for (int k = 0; k < b.size(); k ++) {
                        for (int j = 0; j < b[0].size(); j ++) {
                                c[i][j] = (c[i][j] + a[i][k] * b[k][j] % MOD) % MOD;
                        }
                }
        }
        return c;
}
Matrix Pow(Matrix a, long long n) {
        assert(a.size() == a[0].size());
        Matrix b(a.size(), vector<Type> (a.size()));
        for (int i = 0; i < a.size(); i ++) {
                b[i][i] = 1;
        }
        while (n > 0) {
                if (n & 1) b = Mul(b, a);
                a = Mul(a, a);
                n >>= 1;
        }
        return b;
}


void PrintMatrix(const Matrix &a) {
        int h = a.size(), w = a[0].size();
        for (int i = 0; i < h; i ++) {
                for (int j = 0; j < w; j ++) {
                        cout << a[i][j] << ' ';
                }
                cout << endl;
        }
}


int main() {
    ll N, M, T;
    cin >> N >> M >> T;
    
    vector<vector<ll>> mat(N, vector<ll>(N, 0));
    rep (i, 0, M) {
        int s, t;
        cin >> s >> t;
        mat[s][t] = mat[t][s] = 1;
    }
    
    mat = Pow(move(mat), T);
    
    ll ans = mat[0][0] % MOD;
    if (ans < 0) ans += MOD;
    cout << ans;
    
    return 0;
}
0