結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-04-29 21:02:50 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 301 ms / 5,000 ms |
| コード長 | 959 bytes |
| 記録 | |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 20,956 KB |
| 実行使用メモリ | 21,112 KB |
| 最終ジャッジ日時 | 2026-04-20 12:02:59 |
| 合計ジャッジ時間 | 3,691 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#!/usr/bin/env python3
import array
import collections
Edge = collections.namedtuple("Edge", "source dest")
def possible_current_vertices(n, cost_to_edges, ds):
possible_vertices = []
possible_vertices.append(set(range(1, n + 1)))
for index, d in enumerate(ds, start=1):
vertices = {edge.dest for edge in cost_to_edges[
d] if edge.source in possible_vertices[index - 1]}
possible_vertices.append(vertices)
return possible_vertices[-1]
def main():
n, m, k = map(int, input().split())
cost_to_edges = collections.defaultdict(set)
for _ in range(m):
a, b, c = map(int, input().split())
cost_to_edges[c].add(Edge(a, b))
cost_to_edges[c].add(Edge(b, a))
ds = array.array("L", map(int, input().split()))
answer = possible_current_vertices(n, cost_to_edges, ds)
print(len(answer))
print(" ".join(map(str, sorted(answer))))
if __name__ == '__main__':
main()
はむ吉🐹