結果

問題 No.17 2つの地点に泊まりたい
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-05-30 14:38:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 522 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 16,240 KB
最終ジャッジ日時 2023-10-17 18:52:35
合計ジャッジ時間 3,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,052 KB
testcase_01 AC 85 ms
16,056 KB
testcase_02 AC 88 ms
16,056 KB
testcase_03 AC 118 ms
16,160 KB
testcase_04 AC 92 ms
16,056 KB
testcase_05 AC 100 ms
16,180 KB
testcase_06 AC 97 ms
16,056 KB
testcase_07 AC 92 ms
16,056 KB
testcase_08 AC 107 ms
16,224 KB
testcase_09 AC 108 ms
16,224 KB
testcase_10 AC 104 ms
16,232 KB
testcase_11 AC 107 ms
16,240 KB
testcase_12 AC 82 ms
16,056 KB
testcase_13 AC 82 ms
16,056 KB
testcase_14 AC 83 ms
16,056 KB
testcase_15 AC 85 ms
16,056 KB
testcase_16 AC 85 ms
16,056 KB
testcase_17 AC 90 ms
16,160 KB
testcase_18 AC 110 ms
16,160 KB
testcase_19 AC 108 ms
16,160 KB
testcase_20 AC 87 ms
16,056 KB
testcase_21 AC 86 ms
16,056 KB
testcase_22 AC 112 ms
16,160 KB
testcase_23 AC 99 ms
16,184 KB
testcase_24 AC 102 ms
16,176 KB
testcase_25 AC 85 ms
16,056 KB
testcase_26 AC 105 ms
16,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
s = n.times.map{ gets.to_i }
m = gets.to_i
a, b, c = m.times.map{ gets.split.map(&:to_i) }.transpose

wf = Array.new(n){ Array.new(n, Float::INFINITY) }
n.times{|i| wf[i][i] = 0 }
m.times{|i| wf[a[i]][b[i]] = wf[b[i]][a[i]] = c[i]}
n.times do |k|
  n.times do |i|
    n.times do |j|
      wf[i][j] = [wf[i][j], wf[i][k] + wf[k][j]].min
    end
  end 
end

ans = [*1..(n - 2)].permutation(2)
                   .map{|x, y| (wf[0][x] + wf[x][y] + wf[y][n - 1]) + (s[x] + s[y])}
                   .min
puts ans
0