結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-18 09:00:05 |
| 言語 | Python3 (3.14.2 + numpy 2.4.0 + scipy 1.16.3) |
| 結果 |
AC
|
| 実行時間 | 255 ms / 5,000 ms |
| コード長 | 884 bytes |
| 記録 | |
| コンパイル時間 | 1,006 ms |
| コンパイル使用メモリ | 20,800 KB |
| 実行使用メモリ | 15,488 KB |
| 最終ジャッジ日時 | 2026-01-18 09:00:15 |
| 合計ジャッジ時間 | 5,083 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
from collections import defaultdict
def main():
N, M, K = map(int, input().split())
# 料金ごとに道路をまとめる
edges_by_cost = defaultdict(list)
for _ in range(M):
a, b, c = map(int, input().split())
edges_by_cost[c].append((a, b))
d = list(map(int, input().split()))
# 1回目の通行料金
possible = set()
for a, b in edges_by_cost[d[0]]:
possible.add(a)
possible.add(b)
# 2回目以降
for i in range(1, K):
next_possible = set()
for a, b in edges_by_cost[d[i]]:
if a in possible:
next_possible.add(b)
if b in possible:
next_possible.add(a)
possible = next_possible
# 出力
result = sorted(possible)
print(len(result))
print(" ".join(map(str, result)))
if __name__ == "__main__":
main()