結果

問題 No.92 逃走経路
ユーザー finefine
提出日時 2016-03-26 01:53:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 534 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 38,584 KB
最終ジャッジ日時 2023-08-27 01:35:42
合計ジャッジ時間 5,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
16,692 KB
testcase_01 AC 84 ms
15,256 KB
testcase_02 AC 85 ms
15,064 KB
testcase_03 AC 84 ms
15,248 KB
testcase_04 AC 84 ms
15,160 KB
testcase_05 AC 483 ms
38,584 KB
testcase_06 AC 259 ms
15,280 KB
testcase_07 AC 261 ms
15,356 KB
testcase_08 AC 87 ms
15,496 KB
testcase_09 AC 137 ms
17,200 KB
testcase_10 AC 513 ms
33,856 KB
testcase_11 AC 484 ms
33,376 KB
testcase_12 AC 534 ms
33,652 KB
testcase_13 AC 115 ms
16,632 KB
testcase_14 AC 128 ms
16,528 KB
testcase_15 AC 161 ms
17,024 KB
testcase_16 AC 155 ms
16,420 KB
testcase_17 AC 193 ms
16,636 KB
testcase_18 AC 205 ms
15,988 KB
testcase_19 AC 198 ms
15,396 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:17: warning: assigned but unused variable - k
Syntax OK

ソースコード

diff #

def sol c, d, list
    if d.empty?
        return c
    end
    x = d.shift
    ans = []
    c.each{|s|
        list[s][0].each_with_index{|v,i|
            if v == x
                ans.push(list[s][1][i])
            end
            }
        }
    return sol(ans.uniq, d, list)
end
    
n,m,k = gets.split.map(&:to_i)
fee = Hash.new([])
list = Array.new(n)
n.times{|i|
    list[i] = Array.new(2)
    list[i][0] = []
    list[i][1] = []
    }
m.times{
    a,b,c = gets.split.map(&:to_i)
    fee[c] = fee[c] + [a - 1,b - 1]
    list[a - 1][0].push(c)
    list[a - 1][1].push(b - 1)
    list[b - 1][0].push(c)
    list[b - 1][1].push(a - 1)
    }
d = gets.split.map(&:to_i)
x = d.shift
ans = sol(fee[x].uniq, d, list).map{|i|i + 1}.sort
p ans.size
puts ans.join(' ')
0