結果

問題 No.1749 ラムドスウイルスの感染拡大
ユーザー lloyzlloyz
提出日時 2021-11-19 22:10:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 763 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 93,128 KB
最終ジャッジ日時 2023-08-30 08:43:33
合計ジャッジ時間 4,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
75,704 KB
testcase_01 AC 69 ms
71,324 KB
testcase_02 AC 74 ms
75,664 KB
testcase_03 AC 70 ms
71,308 KB
testcase_04 AC 114 ms
76,348 KB
testcase_05 AC 68 ms
71,460 KB
testcase_06 AC 71 ms
71,340 KB
testcase_07 AC 70 ms
71,256 KB
testcase_08 AC 77 ms
75,160 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, t = map(int, input().split())
M = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    M[a][b] = 1
    M[b][a] = 1
mod = 998244353

def matmul(A, B):
    Ah, Bh, Bw = len(A), len(B), len(B[0])
    C = [[0 for _ in range(Bw)] for _ in range(Ah)]
    for i in range(Ah):
        for j in range(Bw):
            for k in range(Bh):
                C[i][j] += A[i][k] * B[k][j]
                C[i][j] %= mod
    return C

# Mのk乗を効率的に計算する
def doubling(M, k):
    k -= 1
    Mc = M.copy()
    while k > 0:
        if k & 1 == 1:
            Mc = matmul(Mc, M)
        M = matmul(M, M) # Mの(2のi乗)の乗 を計算する
        k >>= 1
    return Mc

Mt = doubling(M, t)
print(Mt[0][0])
0