結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー sten_sansten_san
提出日時 2021-11-19 22:04:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 2,451 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 215,380 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 08:33:13
合計ジャッジ時間 6,546 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 42 ms
4,384 KB
testcase_09 AC 42 ms
4,380 KB
testcase_10 AC 42 ms
4,380 KB
testcase_11 AC 32 ms
4,380 KB
testcase_12 AC 44 ms
4,380 KB
testcase_13 AC 41 ms
4,380 KB
testcase_14 AC 215 ms
4,380 KB
testcase_15 AC 219 ms
4,380 KB
testcase_16 AC 223 ms
4,384 KB
testcase_17 AC 224 ms
4,380 KB
testcase_18 AC 230 ms
4,384 KB
testcase_19 AC 222 ms
4,380 KB
testcase_20 AC 152 ms
4,380 KB
testcase_21 AC 178 ms
4,384 KB
testcase_22 AC 30 ms
4,384 KB
testcase_23 AC 211 ms
4,380 KB
testcase_24 AC 24 ms
4,384 KB
testcase_25 AC 56 ms
4,384 KB
testcase_26 AC 21 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 30 ms
4,384 KB
testcase_31 AC 28 ms
4,384 KB
testcase_32 AC 28 ms
4,380 KB
testcase_33 AC 27 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct iofast_t {
    iofast_t() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} iofast;

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

template <typename T, typename Compare = less<T>>
T &chmin(T &l, T r, Compare &&f = less<T>()) { return l = min(l, r, f); }
template <typename T, typename Compare = less<T>>
T &chmax(T &l, T r, Compare &&f = less<T>()) { return l = max(l, r, f); }

#include <atcoder/modint>
using mint = atcoder::modint998244353;

using matrix = vector<vector<mint>>;

auto melem(const matrix &mat) {
    matrix m = mat;
    for (int i = 0; i < size(m); ++i) {
        for (int j = 0; j < size(m[0]); ++j) {
            m[i][j] = (i == j);
        }
    }
    return m;
}

auto mmul(matrix l, matrix r) {
    int h = size(l);
    int w = size(r[0]);
    int s = size(l[0]);

    matrix m;

    m.resize(h);
    for (auto &r : m) {
        r.resize(w);
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            m[i][j] = 0;
            for (int k = 0; k < s; ++k) {
                m[i][j] += l[i][k] * r[k][j];
            }
        }
    }

    return m;
}

auto mpow(matrix l, int64_t x) {
    matrix r = melem(l);
    while (0 < x) {
        if (x & 1) {
            r = mmul(r, l);
        }
        l = mmul(l, l);
        x >>= 1;
    }
    return r;
}

int main() {
    int64_t n, m, t; cin >> n >> m >> t;
    auto g = vec<int>(uns, n, 0);
    for (int i = 0; i < m; ++i) {
        int s, t; cin >> s >> t;
        g[s].push_back(t);
        g[t].push_back(s);
    }

    matrix dp;

    dp.resize(n);
    for (auto &r : dp) {
        r.resize(n);
    }

    for (auto &u : dp) {
        for (auto &v : u) {
            v = 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (auto v : g[i]) {
            dp[i][v] = 1;
        }
    }

    matrix mat;

    mat.resize(n);
    for (auto &v : mat) {
        v.resize(1);
        v[0] = 0;
    }

    mat[0][0] = 1;

    auto ans = mmul(mpow(dp, t), mat);

    cout << ans[0][0].val() << endl;
}

0