結果
| 問題 | 
                            No.92 逃走経路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-11-02 23:51:35 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 524 bytes | 
| コンパイル時間 | 41 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 26,624 KB | 
| 最終ジャッジ日時 | 2024-11-22 14:23:02 | 
| 合計ジャッジ時間 | 81,579 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 6 TLE * 12 | 
コンパイルメッセージ
Syntax OK
ソースコード
N, M, K = gets.split.map &:to_i
edges = []
M.times.map{
  a, b, c = gets.split.map &:to_i
  edges << [a, b, c] << [b, a, c]
}
tollages = gets.split.map &:to_i
starts = []
edges.each{|a,b,c|
  starts << a if c == tollages[0]
}
starts.uniq!
checked = [false] * -~N
dfs = ->pos, i{
  if i == K
    checked[pos] = true
    return
  end
  edges.each{|a,b,c|
    next if c != tollages[i]
    next if a != pos
    dfs[b, i+1]
  }
}
starts.each{|start|
  dfs[start, 1]
}
p checked.count(true)
puts (1..N).select{|i|checked[i]}*" "