結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
13,312 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 36 ms
11,264 KB
testcase_06 AC 39 ms
11,520 KB
testcase_07 AC 39 ms
11,520 KB
testcase_08 AC 32 ms
11,136 KB
testcase_09 AC 61 ms
19,072 KB
testcase_10 AC 405 ms
13,440 KB
testcase_11 AC 368 ms
13,312 KB
testcase_12 AC 82 ms
19,072 KB
testcase_13 AC 47 ms
13,056 KB
testcase_14 AC 57 ms
13,056 KB
testcase_15 AC 63 ms
13,312 KB
testcase_16 AC 61 ms
13,056 KB
testcase_17 AC 61 ms
13,184 KB
testcase_18 AC 50 ms
13,184 KB
testcase_19 AC 44 ms
11,904 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):
        possible_vertices.append(set())
        for edge in cost_to_edges[d]:
            if edge.source in possible_vertices[index - 1]:
                possible_vertices[index].add(edge.dest)
    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