結果

問題 No.92 逃走経路
ユーザー finefine
提出日時 2016-03-26 01:44:19
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 32 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-04-09 23:54:31
合計ジャッジ時間 2,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 82 ms
12,160 KB
testcase_02 AC 82 ms
12,160 KB
testcase_03 AC 81 ms
12,160 KB
testcase_04 AC 77 ms
12,288 KB
testcase_05 AC 91 ms
18,304 KB
testcase_06 AC 95 ms
12,544 KB
testcase_07 AC 95 ms
12,672 KB
testcase_08 AC 84 ms
12,416 KB
testcase_09 AC 108 ms
16,128 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:16: 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|
        idx = list[s][0].index(x)
        if idx
            ans.push(list[s][1][idx])
        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], d, list).map{|i|i + 1}.sort
p ans.size
puts ans.join(' ')
0