結果

問題 No.1340 おーじ君をさがせ
ユーザー convexineqconvexineq
提出日時 2021-01-15 21:52:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 861 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 81,044 KB
最終ジャッジ日時 2023-08-18 16:35:13
合計ジャッジ時間 15,057 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,212 KB
testcase_01 AC 67 ms
71,280 KB
testcase_02 AC 66 ms
71,128 KB
testcase_03 AC 65 ms
71,124 KB
testcase_04 AC 65 ms
71,080 KB
testcase_05 AC 65 ms
71,248 KB
testcase_06 AC 63 ms
71,312 KB
testcase_07 AC 65 ms
71,124 KB
testcase_08 AC 64 ms
71,360 KB
testcase_09 AC 65 ms
71,140 KB
testcase_10 AC 77 ms
76,024 KB
testcase_11 AC 184 ms
76,964 KB
testcase_12 AC 92 ms
76,388 KB
testcase_13 AC 285 ms
78,008 KB
testcase_14 AC 293 ms
77,252 KB
testcase_15 AC 257 ms
77,228 KB
testcase_16 AC 87 ms
76,444 KB
testcase_17 AC 133 ms
77,308 KB
testcase_18 AC 190 ms
76,872 KB
testcase_19 AC 76 ms
76,256 KB
testcase_20 AC 73 ms
75,932 KB
testcase_21 AC 194 ms
77,936 KB
testcase_22 AC 861 ms
81,044 KB
testcase_23 AC 191 ms
77,868 KB
testcase_24 AC 655 ms
80,644 KB
testcase_25 AC 90 ms
77,564 KB
testcase_26 AC 83 ms
76,616 KB
testcase_27 AC 83 ms
76,620 KB
testcase_28 AC 96 ms
77,764 KB
testcase_29 AC 77 ms
76,672 KB
testcase_30 AC 198 ms
78,136 KB
testcase_31 AC 669 ms
80,464 KB
testcase_32 AC 646 ms
80,652 KB
testcase_33 AC 624 ms
80,612 KB
testcase_34 AC 557 ms
80,840 KB
testcase_35 AC 660 ms
80,716 KB
testcase_36 AC 67 ms
71,156 KB
testcase_37 AC 71 ms
77,644 KB
testcase_38 AC 655 ms
80,520 KB
testcase_39 AC 219 ms
78,624 KB
testcase_40 AC 228 ms
78,680 KB
testcase_41 AC 227 ms
78,660 KB
testcase_42 AC 72 ms
76,004 KB
testcase_43 AC 67 ms
75,288 KB
testcase_44 AC 72 ms
76,024 KB
testcase_45 AC 70 ms
76,148 KB
testcase_46 AC 185 ms
77,260 KB
testcase_47 AC 195 ms
77,284 KB
testcase_48 AC 210 ms
77,240 KB
testcase_49 AC 199 ms
76,944 KB
testcase_50 AC 205 ms
77,056 KB
testcase_51 AC 211 ms
76,884 KB
testcase_52 AC 326 ms
77,156 KB
testcase_53 AC 317 ms
77,152 KB
testcase_54 AC 322 ms
76,768 KB
testcase_55 AC 261 ms
77,120 KB
testcase_56 AC 71 ms
76,384 KB
testcase_57 AC 74 ms
75,996 KB
testcase_58 AC 66 ms
71,244 KB
testcase_59 AC 142 ms
76,100 KB
testcase_60 AC 65 ms
71,412 KB
testcase_61 AC 143 ms
76,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def matmul(A,B): # A,B: 行列
    n = len(A)
    res = [[0]*n for _ in range(n)]
    for i in range(n):
        for k in range(n):
            for j in range(n):
                res[i][j] |= A[i][k]&B[k][j]
    return res

def matpow(A,p): #A^p mod M
    if p%2:
        return matmul(A, matpow(A,p-1))
    elif p > 0:
        b = matpow(A,p//2)
        return matmul(b,b)
    else:
        return [[1 if i == j else 0 for j in range(len(A))] for i in range(len(A))]

n,m,t,*ab = map(int,open(0).read().split())
g = [[0]*n for _ in range(n)]
for i in range(m):
    g[ab[i*2]][ab[i*2+1]]=1
A = matpow(g,t)
print(sum(A[0]))
0