結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー H3PO4
提出日時 2021-11-19 21:43:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 524 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 95,988 KB
最終ジャッジ日時 2024-12-31 22:32:57
合計ジャッジ時間 57,064 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

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


def pow_matrix_mod(x, n, mod=MOD):
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


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

matr = np.array(matr, dtype=object)
print(pow_matrix_mod(matr, T)[0, 0])
0