結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー H3PO4H3PO4
提出日時 2021-11-19 21:46:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 818 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 101,080 KB
最終ジャッジ日時 2023-08-30 08:00:51
合計ジャッジ時間 8,543 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,292 KB
testcase_01 AC 73 ms
71,404 KB
testcase_02 AC 76 ms
75,276 KB
testcase_03 AC 77 ms
76,292 KB
testcase_04 AC 192 ms
77,740 KB
testcase_05 AC 71 ms
71,344 KB
testcase_06 AC 72 ms
71,396 KB
testcase_07 AC 71 ms
71,296 KB
testcase_08 AC 566 ms
79,744 KB
testcase_09 AC 540 ms
79,368 KB
testcase_10 AC 576 ms
79,720 KB
testcase_11 AC 566 ms
80,136 KB
testcase_12 AC 677 ms
81,180 KB
testcase_13 AC 748 ms
80,832 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, T = map(int, input().split())
MOD = 998244353

"""行列累乗を https://qiita.com/ophhdn/items/e6451ec5983939ecbc5b から拝借しています"""


def mat_mul(a, b):
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I):
        for j in range(J):
            for k in range(K):
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= MOD
    return c


def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]

    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1

    return y


matr = [[0] * N for _ in range(N)]
for _ in range(M):
    s, t = map(int, input().split())
    matr[s][t] = 1
    matr[t][s] = 1

print(mat_pow(matr, T)[0][0])
0