結果

問題 No.1340 おーじ君をさがせ
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-28 15:56:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 682 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-04-24 19:50:37
合計ジャッジ時間 14,587 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
57,984 KB
testcase_01 AC 45 ms
57,984 KB
testcase_02 AC 41 ms
52,096 KB
testcase_03 AC 40 ms
51,840 KB
testcase_04 AC 37 ms
51,840 KB
testcase_05 AC 36 ms
51,712 KB
testcase_06 AC 37 ms
52,224 KB
testcase_07 AC 37 ms
52,224 KB
testcase_08 AC 40 ms
52,352 KB
testcase_09 AC 45 ms
52,096 KB
testcase_10 AC 53 ms
61,696 KB
testcase_11 AC 182 ms
76,032 KB
testcase_12 AC 76 ms
66,688 KB
testcase_13 AC 150 ms
75,648 KB
testcase_14 AC 299 ms
75,904 KB
testcase_15 AC 260 ms
76,416 KB
testcase_16 AC 66 ms
65,792 KB
testcase_17 AC 127 ms
76,032 KB
testcase_18 AC 192 ms
76,032 KB
testcase_19 AC 61 ms
63,744 KB
testcase_20 AC 52 ms
61,056 KB
testcase_21 AC 201 ms
76,160 KB
testcase_22 AC 415 ms
76,160 KB
testcase_23 AC 186 ms
76,416 KB
testcase_24 AC 682 ms
76,672 KB
testcase_25 AC 77 ms
71,168 KB
testcase_26 AC 70 ms
68,480 KB
testcase_27 AC 67 ms
67,712 KB
testcase_28 AC 79 ms
72,192 KB
testcase_29 AC 65 ms
67,456 KB
testcase_30 AC 198 ms
76,160 KB
testcase_31 AC 671 ms
77,056 KB
testcase_32 AC 622 ms
76,672 KB
testcase_33 AC 618 ms
76,672 KB
testcase_34 AC 571 ms
77,056 KB
testcase_35 AC 668 ms
76,800 KB
testcase_36 AC 41 ms
52,608 KB
testcase_37 AC 51 ms
62,336 KB
testcase_38 AC 666 ms
76,672 KB
testcase_39 AC 221 ms
76,672 KB
testcase_40 AC 241 ms
76,544 KB
testcase_41 AC 232 ms
76,544 KB
testcase_42 AC 45 ms
59,264 KB
testcase_43 AC 50 ms
60,032 KB
testcase_44 AC 47 ms
60,160 KB
testcase_45 AC 47 ms
60,416 KB
testcase_46 AC 196 ms
76,544 KB
testcase_47 AC 195 ms
76,288 KB
testcase_48 AC 202 ms
76,288 KB
testcase_49 AC 198 ms
76,160 KB
testcase_50 AC 195 ms
76,032 KB
testcase_51 AC 200 ms
76,416 KB
testcase_52 AC 323 ms
75,904 KB
testcase_53 AC 314 ms
76,288 KB
testcase_54 AC 323 ms
76,160 KB
testcase_55 AC 270 ms
76,288 KB
testcase_56 AC 50 ms
60,672 KB
testcase_57 AC 50 ms
60,544 KB
testcase_58 AC 43 ms
58,240 KB
testcase_59 AC 136 ms
71,808 KB
testcase_60 AC 37 ms
52,352 KB
testcase_61 AC 135 ms
71,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


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


def mat_pow(A, n):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res


N, M, T = map(int, input().split())
deg = [0] * N
A = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    deg[a] += 1
    A[a][b] = 1
for i in range(N):
    if not deg[i]:
        A[i][N] = 1

B = mat_pow(A, T)
ans = sum(B[0][:N])
print(ans)
0