結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-04-29 21:02:50 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 310 ms / 5,000 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2024-10-04 17:53:00 |
| 合計ジャッジ時間 | 2,172 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()
はむ吉🐹