結果
問題 | No.92 逃走経路 |
ユーザー |
|
提出日時 | 2022-12-06 18:27:17 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 260 ms / 5,000 ms |
コード長 | 1,014 bytes |
コンパイル時間 | 124 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 13,056 KB |
最終ジャッジ日時 | 2024-10-13 07:41:13 |
合計ジャッジ時間 | 2,573 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
from collections import defaultdict, dequefrom typing import Dequedef 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()