結果

問題 No.92 逃走経路
コンテスト
ユーザー はむ吉🐹
提出日時 2016-04-29 21:02:50
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 245 ms / 5,000 ms
+ 321µs
コード長 959 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 159 ms
コンパイル使用メモリ 15,104 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2026-10-13 10:13:29
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/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()
0