結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー brthyyjpbrthyyjp
提出日時 2021-11-24 09:14:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,940 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 77,884 KB
最終ジャッジ日時 2023-09-08 15:21:50
合計ジャッジ時間 24,043 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,248 KB
testcase_01 AC 72 ms
71,464 KB
testcase_02 AC 76 ms
75,168 KB
testcase_03 AC 79 ms
75,896 KB
testcase_04 AC 122 ms
76,208 KB
testcase_05 AC 73 ms
71,448 KB
testcase_06 AC 73 ms
71,332 KB
testcase_07 AC 73 ms
71,144 KB
testcase_08 AC 404 ms
76,976 KB
testcase_09 AC 403 ms
77,068 KB
testcase_10 AC 402 ms
77,192 KB
testcase_11 AC 319 ms
77,052 KB
testcase_12 AC 420 ms
77,360 KB
testcase_13 AC 398 ms
77,048 KB
testcase_14 AC 1,802 ms
77,752 KB
testcase_15 AC 1,841 ms
77,444 KB
testcase_16 AC 1,860 ms
77,240 KB
testcase_17 AC 1,882 ms
77,532 KB
testcase_18 AC 1,940 ms
77,884 KB
testcase_19 AC 1,865 ms
77,624 KB
testcase_20 AC 1,304 ms
77,288 KB
testcase_21 AC 1,484 ms
77,496 KB
testcase_22 AC 329 ms
77,064 KB
testcase_23 AC 1,733 ms
77,344 KB
testcase_24 AC 275 ms
76,964 KB
testcase_25 AC 546 ms
77,140 KB
testcase_26 AC 232 ms
76,712 KB
testcase_27 AC 83 ms
75,988 KB
testcase_28 AC 96 ms
76,988 KB
testcase_29 AC 84 ms
76,256 KB
testcase_30 AC 325 ms
77,116 KB
testcase_31 AC 310 ms
76,800 KB
testcase_32 AC 304 ms
76,908 KB
testcase_33 AC 299 ms
76,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# A*B
def mat_mul(A, B, mod):
    C = [[0]*len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for j in range(len(B[0])):
            temp = 0
            for k in range(len(A[0])):
                temp = (temp + A[i][k]*B[k][j])%mod
            C[i][j] = temp
    return C

#A**n
def mat_pow(A, n, mod):
    B = [[0]*len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    for i in range(n.bit_length()):
        if (n >> i)&1:
            B = mat_mul(A, B, mod)
        A = mat_mul(A, A, mod)
    return B

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
mod = 998244353

def main():

    n, m, t = map(int, input().split())
    A = [[0]*n for i in range(n)]
    for i in range(m):
        u, v = map(int, input().split())
        A[u][v] = 1
        A[v][u] = 1

    A = mat_pow(A, t, mod)
    print(A[0][0]%mod)

if __name__ == '__main__':
    main()
0