結果

問題 No.1340 おーじ君をさがせ
ユーザー nephrologistnephrologist
提出日時 2021-01-15 23:51:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 855 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 81,484 KB
最終ジャッジ日時 2023-08-18 16:48:27
合計ジャッジ時間 15,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,488 KB
testcase_01 AC 68 ms
71,560 KB
testcase_02 AC 64 ms
71,356 KB
testcase_03 AC 65 ms
71,352 KB
testcase_04 AC 66 ms
71,276 KB
testcase_05 AC 64 ms
71,472 KB
testcase_06 AC 65 ms
71,516 KB
testcase_07 AC 66 ms
71,380 KB
testcase_08 AC 65 ms
71,320 KB
testcase_09 AC 64 ms
71,428 KB
testcase_10 AC 73 ms
76,260 KB
testcase_11 AC 186 ms
76,884 KB
testcase_12 AC 93 ms
76,464 KB
testcase_13 AC 286 ms
77,960 KB
testcase_14 AC 329 ms
77,192 KB
testcase_15 AC 265 ms
77,008 KB
testcase_16 AC 89 ms
76,468 KB
testcase_17 AC 141 ms
76,912 KB
testcase_18 AC 191 ms
77,092 KB
testcase_19 AC 80 ms
76,496 KB
testcase_20 AC 74 ms
76,280 KB
testcase_21 AC 192 ms
77,240 KB
testcase_22 AC 855 ms
81,484 KB
testcase_23 AC 192 ms
77,416 KB
testcase_24 AC 687 ms
77,784 KB
testcase_25 AC 94 ms
76,600 KB
testcase_26 AC 84 ms
76,788 KB
testcase_27 AC 81 ms
76,688 KB
testcase_28 AC 97 ms
77,136 KB
testcase_29 AC 82 ms
76,500 KB
testcase_30 AC 214 ms
77,504 KB
testcase_31 AC 682 ms
77,900 KB
testcase_32 AC 686 ms
77,864 KB
testcase_33 AC 638 ms
77,980 KB
testcase_34 AC 575 ms
77,944 KB
testcase_35 AC 691 ms
78,140 KB
testcase_36 AC 66 ms
71,376 KB
testcase_37 AC 71 ms
76,152 KB
testcase_38 AC 683 ms
77,872 KB
testcase_39 AC 226 ms
77,508 KB
testcase_40 AC 240 ms
77,536 KB
testcase_41 AC 240 ms
77,636 KB
testcase_42 AC 71 ms
76,120 KB
testcase_43 AC 68 ms
76,180 KB
testcase_44 AC 70 ms
76,256 KB
testcase_45 AC 70 ms
76,220 KB
testcase_46 AC 203 ms
77,700 KB
testcase_47 AC 206 ms
77,584 KB
testcase_48 AC 216 ms
77,412 KB
testcase_49 AC 212 ms
77,200 KB
testcase_50 AC 209 ms
77,272 KB
testcase_51 AC 213 ms
77,160 KB
testcase_52 AC 352 ms
77,224 KB
testcase_53 AC 333 ms
77,472 KB
testcase_54 AC 342 ms
77,176 KB
testcase_55 AC 282 ms
77,412 KB
testcase_56 AC 71 ms
76,132 KB
testcase_57 AC 70 ms
76,172 KB
testcase_58 AC 63 ms
71,416 KB
testcase_59 AC 154 ms
76,356 KB
testcase_60 AC 66 ms
71,348 KB
testcase_61 AC 161 ms
77,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline
#  nxnの行列積
# n is necessary


n, m, t = map(int, input().split())

graph = [[0] * (n) for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a][b] = 1


def matrix_product(A, B):
    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]
    for i in range(n):
        for j in range(n):
            if res[i][j]:
                res[i][j] = 1
    return res


def matrix_exponents(A, t):
    res = [[0] * n for _ in range(n)]
    for i in range(n):
        res[i][i] = 1

    while t > 0:
        if t & 1 == 1:
            res = matrix_product(res, A)
        A = matrix_product(A, A)
        t //= 2
    return res


res = matrix_exponents(graph, t)
ans = 0

for j in range(n):
    if res[0][j]:
        ans += 1

print(ans)
0