結果

問題 No.1340 おーじ君をさがせ
ユーザー nephrologistnephrologist
提出日時 2021-01-15 23:32:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 948 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 80,896 KB
最終ジャッジ日時 2024-05-05 03:05:38
合計ジャッジ時間 15,141 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
51,840 KB
testcase_01 AC 35 ms
52,224 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 WA -
testcase_05 AC 40 ms
52,096 KB
testcase_06 WA -
testcase_07 AC 40 ms
52,096 KB
testcase_08 AC 40 ms
52,096 KB
testcase_09 WA -
testcase_10 AC 56 ms
63,872 KB
testcase_11 AC 144 ms
76,032 KB
testcase_12 WA -
testcase_13 AC 216 ms
76,672 KB
testcase_14 AC 205 ms
75,776 KB
testcase_15 AC 199 ms
76,032 KB
testcase_16 AC 79 ms
68,096 KB
testcase_17 AC 104 ms
75,520 KB
testcase_18 AC 144 ms
76,032 KB
testcase_19 AC 62 ms
65,280 KB
testcase_20 AC 59 ms
63,744 KB
testcase_21 AC 328 ms
76,032 KB
testcase_22 AC 1,125 ms
80,896 KB
testcase_23 AC 169 ms
76,160 KB
testcase_24 AC 1,426 ms
76,928 KB
testcase_25 AC 88 ms
72,960 KB
testcase_26 AC 73 ms
69,888 KB
testcase_27 AC 61 ms
69,376 KB
testcase_28 AC 102 ms
73,856 KB
testcase_29 AC 56 ms
65,792 KB
testcase_30 AC 352 ms
76,288 KB
testcase_31 AC 1,971 ms
77,056 KB
testcase_32 AC 434 ms
76,544 KB
testcase_33 AC 422 ms
76,672 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 37 ms
52,480 KB
testcase_37 AC 45 ms
62,208 KB
testcase_38 WA -
testcase_39 AC 180 ms
76,544 KB
testcase_40 AC 172 ms
76,288 KB
testcase_41 AC 184 ms
76,160 KB
testcase_42 WA -
testcase_43 AC 40 ms
58,112 KB
testcase_44 AC 47 ms
61,184 KB
testcase_45 AC 44 ms
59,520 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 256 ms
76,288 KB
testcase_49 AC 183 ms
76,032 KB
testcase_50 AC 181 ms
76,032 KB
testcase_51 AC 184 ms
76,416 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 45 ms
59,776 KB
testcase_57 AC 43 ms
59,392 KB
testcase_58 AC 36 ms
52,480 KB
testcase_59 WA -
testcase_60 AC 36 ms
52,224 KB
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

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())
    a, b = a - 1, b - 1
    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] and 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 - 1)
ans = 0

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

print(ans)
0