結果

問題 No.17 2つの地点に泊まりたい
ユーザー TANIGUCHI Kousuke
提出日時 2015-06-03 18:27:13
言語 Ruby
(3.4.1)
結果
AC  
実行時間 116 ms / 5,000 ms
コード長 708 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-10-15 01:20:44
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:5: warning: assigned but unused variable - v
Syntax OK

ソースコード

diff #

# Here your code !
INF = 1000000

n = gets.to_i
v = {}

stay = n.times.map { gets.to_i }
edge = n.times.map { Array.new(n,INF) }

n.times do |i|
    edge[i][i] = 0
end

m = gets.to_i

m.times do 
    from,to,cost = gets.split.map(&:to_i)
    edge[from][to] = cost
    edge[to][from] = cost
end

n.times do |k|
    n.times do |j|
        n.times do |i|
            edge[i][j] = [edge[i][j], edge[i][k] + edge[k][j]].min
        end
    end
end

cost = n.times.map { Array.new(n,INF) }
(1..n-2).to_a.combination(2) do |(i,j)|
    cost[i][j] = edge[0][i] + edge[i][j] + edge[j][n-1] + stay[i] + stay[j]
    cost[j][i] = edge[0][j] + edge[j][i] + edge[i][n-1] + stay[i] + stay[j]
end

puts cost.flatten.uniq.min
0