結果

問題 No.1340 おーじ君をさがせ
ユーザー H3PO4H3PO4
提出日時 2021-01-15 22:41:40
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 34,476 KB
最終ジャッジ日時 2023-08-18 16:41:45
合計ジャッジ時間 11,795 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
29,732 KB
testcase_01 AC 127 ms
29,744 KB
testcase_02 AC 128 ms
29,816 KB
testcase_03 AC 127 ms
29,772 KB
testcase_04 AC 128 ms
29,800 KB
testcase_05 AC 126 ms
29,856 KB
testcase_06 AC 125 ms
29,724 KB
testcase_07 AC 127 ms
29,868 KB
testcase_08 AC 126 ms
29,760 KB
testcase_09 AC 126 ms
29,852 KB
testcase_10 AC 126 ms
29,708 KB
testcase_11 AC 141 ms
30,664 KB
testcase_12 AC 129 ms
30,156 KB
testcase_13 AC 138 ms
30,320 KB
testcase_14 AC 161 ms
31,760 KB
testcase_15 AC 158 ms
31,504 KB
testcase_16 AC 134 ms
30,044 KB
testcase_17 AC 137 ms
30,392 KB
testcase_18 AC 145 ms
30,732 KB
testcase_19 AC 129 ms
29,864 KB
testcase_20 AC 127 ms
29,672 KB
testcase_21 AC 165 ms
30,976 KB
testcase_22 AC 187 ms
32,636 KB
testcase_23 AC 166 ms
30,944 KB
testcase_24 AC 213 ms
34,232 KB
testcase_25 AC 156 ms
30,076 KB
testcase_26 AC 144 ms
29,992 KB
testcase_27 AC 140 ms
29,804 KB
testcase_28 AC 154 ms
30,176 KB
testcase_29 AC 142 ms
29,792 KB
testcase_30 AC 174 ms
31,304 KB
testcase_31 AC 235 ms
34,360 KB
testcase_32 AC 229 ms
34,248 KB
testcase_33 AC 230 ms
33,996 KB
testcase_34 AC 223 ms
33,840 KB
testcase_35 AC 238 ms
34,204 KB
testcase_36 AC 129 ms
29,796 KB
testcase_37 AC 153 ms
29,856 KB
testcase_38 AC 232 ms
34,476 KB
testcase_39 AC 176 ms
31,044 KB
testcase_40 AC 172 ms
30,784 KB
testcase_41 AC 174 ms
30,816 KB
testcase_42 AC 126 ms
29,676 KB
testcase_43 AC 126 ms
29,784 KB
testcase_44 AC 127 ms
29,684 KB
testcase_45 AC 126 ms
29,748 KB
testcase_46 AC 150 ms
30,436 KB
testcase_47 AC 153 ms
30,784 KB
testcase_48 AC 153 ms
30,740 KB
testcase_49 AC 145 ms
30,816 KB
testcase_50 AC 144 ms
31,076 KB
testcase_51 AC 145 ms
31,024 KB
testcase_52 AC 163 ms
31,844 KB
testcase_53 AC 165 ms
31,708 KB
testcase_54 AC 163 ms
31,836 KB
testcase_55 AC 158 ms
31,172 KB
testcase_56 AC 125 ms
29,856 KB
testcase_57 AC 126 ms
29,720 KB
testcase_58 AC 125 ms
29,740 KB
testcase_59 AC 138 ms
30,272 KB
testcase_60 AC 126 ms
29,760 KB
testcase_61 AC 136 ms
30,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def pow_matrix_mod(x, n):
    if not n:
        return np.eye(len(x), dtype=int)
    if n % 2 == 0:
        return pow_matrix_mod(np.where((x @ x) != 0, 1, 0), n // 2)
    else:
        tmp = pow_matrix_mod(np.where((x @ x) != 0, 1, 0), (n - 1) // 2)
        return np.where((x @ tmp) != 0, 1, 0)


N, M, T = map(int, input().split())
matr = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    matr[a][b] = 1
matr = np.array(matr)

first = np.zeros(N, dtype=int)
first[0] = 1

ans = np.count_nonzero(first @ pow_matrix_mod(matr, T))
print(ans)
0