結果

問題 No.92 逃走経路
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-04-29 21:02:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 337 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-15 05:27:42
合計ジャッジ時間 2,267 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
13,312 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 33 ms
11,136 KB
testcase_06 AC 34 ms
11,392 KB
testcase_07 AC 34 ms
11,520 KB
testcase_08 AC 30 ms
11,136 KB
testcase_09 AC 55 ms
19,072 KB
testcase_10 AC 337 ms
13,440 KB
testcase_11 AC 308 ms
13,440 KB
testcase_12 AC 74 ms
19,072 KB
testcase_13 AC 44 ms
13,184 KB
testcase_14 AC 51 ms
13,184 KB
testcase_15 AC 56 ms
13,184 KB
testcase_16 AC 53 ms
13,056 KB
testcase_17 AC 55 ms
13,184 KB
testcase_18 AC 46 ms
13,056 KB
testcase_19 AC 40 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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