結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー hir355hir355
提出日時 2021-11-19 21:43:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,816 ms / 2,000 ms
コード長 566 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 30,092 KB
最終ジャッジ日時 2023-08-30 07:54:09
合計ジャッジ時間 25,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
29,568 KB
testcase_01 AC 138 ms
29,544 KB
testcase_02 AC 139 ms
29,600 KB
testcase_03 AC 140 ms
29,656 KB
testcase_04 AC 180 ms
29,716 KB
testcase_05 AC 139 ms
29,608 KB
testcase_06 AC 134 ms
29,636 KB
testcase_07 AC 134 ms
29,656 KB
testcase_08 AC 428 ms
29,868 KB
testcase_09 AC 431 ms
30,092 KB
testcase_10 AC 432 ms
29,936 KB
testcase_11 AC 363 ms
29,988 KB
testcase_12 AC 438 ms
30,044 KB
testcase_13 AC 425 ms
30,024 KB
testcase_14 AC 1,621 ms
30,040 KB
testcase_15 AC 1,660 ms
30,024 KB
testcase_16 AC 1,681 ms
29,956 KB
testcase_17 AC 1,748 ms
30,072 KB
testcase_18 AC 1,816 ms
29,908 KB
testcase_19 AC 1,728 ms
29,960 KB
testcase_20 AC 1,240 ms
30,024 KB
testcase_21 AC 1,391 ms
29,872 KB
testcase_22 AC 394 ms
29,724 KB
testcase_23 AC 1,586 ms
29,888 KB
testcase_24 AC 334 ms
29,676 KB
testcase_25 AC 577 ms
29,788 KB
testcase_26 AC 296 ms
29,736 KB
testcase_27 AC 144 ms
29,684 KB
testcase_28 AC 155 ms
29,664 KB
testcase_29 AC 142 ms
29,740 KB
testcase_30 AC 379 ms
29,644 KB
testcase_31 AC 362 ms
29,680 KB
testcase_32 AC 358 ms
29,616 KB
testcase_33 AC 354 ms
29,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
MOD = 998244353
 
 
def mult(N, A, B):
    C = np.zeros((N, N), np.int64)
    for n in range(N):
        C[n] = (A[n, :][:, None] * B % MOD).sum(axis=0) % MOD
    return C
 
 
def mat_power(A, N, k):
    if k == 0:
        return np.eye(N, dtype=np.int64)
    X = mat_power(A, N, k//2)
    X = mult(N, X, X)
    return mult(N, A, X) if k & 1 else X
 
 
n, m, tt = map(int, input().split())
a = np.zeros((n, n), np.int64)
for i in range(m):
    s, t = map(int, input().split())
    a[s][t] = 1
    a[t][s] = 1
print(mat_power(a, n, tt)[0][0] % MOD)
0