結果

問題 No.1340 おーじ君をさがせ
ユーザー ayaoniayaoni
提出日時 2021-01-16 02:50:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 884 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 81,608 KB
最終ジャッジ日時 2023-08-18 16:52:31
合計ジャッジ時間 16,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,216 KB
testcase_01 AC 80 ms
71,364 KB
testcase_02 AC 73 ms
71,500 KB
testcase_03 AC 80 ms
71,496 KB
testcase_04 AC 82 ms
71,412 KB
testcase_05 AC 76 ms
71,564 KB
testcase_06 AC 76 ms
71,224 KB
testcase_07 AC 82 ms
71,056 KB
testcase_08 AC 78 ms
71,456 KB
testcase_09 AC 80 ms
71,336 KB
testcase_10 AC 112 ms
76,348 KB
testcase_11 AC 204 ms
77,060 KB
testcase_12 AC 100 ms
75,980 KB
testcase_13 AC 288 ms
77,628 KB
testcase_14 AC 317 ms
77,220 KB
testcase_15 AC 284 ms
77,152 KB
testcase_16 AC 99 ms
76,408 KB
testcase_17 AC 147 ms
76,728 KB
testcase_18 AC 205 ms
76,668 KB
testcase_19 AC 89 ms
76,324 KB
testcase_20 AC 84 ms
75,972 KB
testcase_21 AC 208 ms
77,396 KB
testcase_22 AC 884 ms
81,608 KB
testcase_23 AC 198 ms
77,444 KB
testcase_24 AC 750 ms
78,164 KB
testcase_25 AC 103 ms
77,392 KB
testcase_26 AC 95 ms
76,960 KB
testcase_27 AC 92 ms
76,908 KB
testcase_28 AC 111 ms
77,292 KB
testcase_29 AC 88 ms
76,796 KB
testcase_30 AC 219 ms
77,364 KB
testcase_31 AC 726 ms
78,184 KB
testcase_32 AC 675 ms
78,124 KB
testcase_33 AC 688 ms
78,004 KB
testcase_34 AC 622 ms
78,000 KB
testcase_35 AC 737 ms
78,040 KB
testcase_36 AC 76 ms
71,292 KB
testcase_37 AC 86 ms
76,428 KB
testcase_38 AC 752 ms
78,360 KB
testcase_39 AC 244 ms
77,516 KB
testcase_40 AC 271 ms
77,468 KB
testcase_41 AC 261 ms
77,388 KB
testcase_42 AC 82 ms
76,268 KB
testcase_43 AC 81 ms
75,972 KB
testcase_44 AC 81 ms
76,324 KB
testcase_45 AC 83 ms
75,940 KB
testcase_46 AC 215 ms
77,492 KB
testcase_47 AC 217 ms
77,520 KB
testcase_48 AC 265 ms
77,688 KB
testcase_49 AC 223 ms
77,100 KB
testcase_50 AC 224 ms
77,296 KB
testcase_51 AC 218 ms
77,192 KB
testcase_52 AC 361 ms
77,184 KB
testcase_53 AC 352 ms
76,876 KB
testcase_54 AC 358 ms
76,960 KB
testcase_55 AC 296 ms
77,852 KB
testcase_56 AC 72 ms
76,336 KB
testcase_57 AC 74 ms
76,072 KB
testcase_58 AC 66 ms
71,452 KB
testcase_59 AC 158 ms
76,456 KB
testcase_60 AC 64 ms
71,232 KB
testcase_61 AC 153 ms
76,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


def matrix_multiplication(A,B):
    l = len(A)
    m = len(B)
    n = len(B[0])
    C = [[0]*n for _ in range(l)]
    for i in range(l):
        for j in range(n):
            for k in range(m):
                C[i][j] |= A[i][k] & B[k][j]
    return C


def matrix_power(A,n):
    l = len(A)
    C = [[0]*l for _ in range(l)]
    for i in range(l):
        C[i][i] = 1
    while n > 0:
        if n % 2 == 1:
            C = matrix_multiplication(C,A)
        A = matrix_multiplication(A,A)
        n >>= 1
    return C


N,M,T = MI()
Graph = [[0]*N for _ in range(N)]
for _ in range(M):
    a,b = MI()
    Graph[a][b] = 1

X = matrix_power(Graph,T)
ans = sum(X[0])

print(ans)
0