結果

問題 No.92 逃走経路
ユーザー ThetaTheta
提出日時 2022-12-06 18:27:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 288 ms / 5,000 ms
コード長 1,014 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-21 08:49:04
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
13,184 KB
testcase_01 AC 44 ms
11,392 KB
testcase_02 AC 41 ms
11,520 KB
testcase_03 AC 42 ms
11,392 KB
testcase_04 AC 43 ms
11,392 KB
testcase_05 AC 48 ms
11,520 KB
testcase_06 AC 51 ms
12,416 KB
testcase_07 AC 54 ms
12,544 KB
testcase_08 AC 62 ms
12,288 KB
testcase_09 AC 74 ms
12,288 KB
testcase_10 AC 288 ms
12,160 KB
testcase_11 AC 270 ms
12,288 KB
testcase_12 AC 89 ms
12,544 KB
testcase_13 AC 72 ms
12,416 KB
testcase_14 AC 82 ms
12,544 KB
testcase_15 AC 88 ms
12,672 KB
testcase_16 AC 85 ms
12,672 KB
testcase_17 AC 86 ms
12,928 KB
testcase_18 AC 63 ms
12,288 KB
testcase_19 AC 57 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque
from typing import Deque


def main():
    N, M, K = map(int, input().split())
    routes = [list(map(int, input().split())) for _ in range(M)]
    routes_cost_dict = defaultdict(lambda: defaultdict(set))
    for route in routes:
        routes_cost_dict[route[2]][route[0]].add(route[1])
        routes_cost_dict[route[2]][route[1]].add(route[0])
    history = list(map(int, input().split()))

    dp_table = [[False for _ in range(N)] for _ in range(K+1)]
    dp_table[0] = [True for _ in range(N)]

    for ctr, cost in enumerate(history, 1):
        for city_idx in range(1, N+1):
            for dest_city_idx in routes_cost_dict[cost][city_idx]:
                dp_table[ctr][dest_city_idx-1] |= dp_table[ctr-1][city_idx-1]

    last_city_candidates = set(
        filter(lambda city_idx: dp_table[K][city_idx], range(N)))
    print(len(last_city_candidates))
    print(*map(lambda num: num+1, sorted(last_city_candidates)))


if __name__ == "__main__":
    main()
0