結果

問題 No.92 逃走経路
ユーザー magurogumamaguroguma
提出日時 2017-08-18 01:25:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-04-22 14:57:23
合計ジャッジ時間 12,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

from collections import deque

N,M,K = map(int, input().split())
a = [-1]
b = [-1]
c = [-1]
for i in range(M):
    s,t,u = map(int, input().split())
    a.append(s)
    b.append(t)
    c.append(u)
d = list(map(int, input().split()))

answer = []

# スタート町のセット
start_towns = deque()
end_towns = deque()
for i in range(1, M+1):
    if d[0]==c[i]:
        start_towns.append(a[i])
        start_towns.append(b[i])
# スタート町を起点に1ステップずつ幅優先探索
for i in range(1, K):
    es_cost = d[i]
    while len(start_towns) > 0:
        town = start_towns.popleft()
        for j in range(1,M+1):
            if c[j]==es_cost and town == a[j]:
                end_towns.append(b[j])
            elif c[j]==es_cost and town == b[j]:
                end_towns.append(a[j])
    if i < K-1:
        start_towns = end_towns
        end_towns = deque()

# end_townsが答え
for t in end_towns:
    answer.append(t)
answer.sort()
print(len(answer))
answer_str = str(answer[0])
for i in range(1, len(answer)):
    answer_str += ' ' + str(answer[i])
print(answer_str)
0