結果
| 問題 | 
                            No.92 逃走経路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-08-18 01:25:00 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,120 bytes | 
| コンパイル時間 | 296 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 24,768 KB | 
| 最終ジャッジ日時 | 2024-10-14 14:02:03 | 
| 合計ジャッジ時間 | 12,965 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 2 | 
| other | TLE * 1 -- * 17 | 
ソースコード
# -*- 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)