結果

問題 No.17 2つの地点に泊まりたい
ユーザー cympfhcympfh
提出日時 2016-03-16 11:25:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 511 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-23 02:12:02
合計ジャッジ時間 3,848 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,288 KB
testcase_01 AC 91 ms
12,160 KB
testcase_02 AC 93 ms
12,288 KB
testcase_03 AC 126 ms
13,056 KB
testcase_04 AC 96 ms
12,160 KB
testcase_05 AC 119 ms
13,056 KB
testcase_06 AC 106 ms
12,160 KB
testcase_07 AC 101 ms
12,416 KB
testcase_08 AC 126 ms
13,312 KB
testcase_09 AC 124 ms
13,312 KB
testcase_10 AC 119 ms
12,928 KB
testcase_11 AC 126 ms
13,312 KB
testcase_12 AC 91 ms
12,160 KB
testcase_13 AC 92 ms
12,160 KB
testcase_14 AC 91 ms
12,160 KB
testcase_15 AC 91 ms
12,160 KB
testcase_16 AC 89 ms
12,288 KB
testcase_17 AC 95 ms
12,416 KB
testcase_18 AC 117 ms
12,800 KB
testcase_19 AC 115 ms
12,928 KB
testcase_20 AC 95 ms
12,416 KB
testcase_21 AC 96 ms
12,288 KB
testcase_22 AC 127 ms
13,056 KB
testcase_23 AC 111 ms
12,928 KB
testcase_24 AC 118 ms
12,928 KB
testcase_25 AC 91 ms
12,160 KB
testcase_26 AC 125 ms
13,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
stay=(1..n).map{gets.to_i}
d=(1..n).map{(1..n).to_a}
(0...n).map{|i|
  (0...n).map{|j| d[i][j]=1e12.to_i}
  d[i][i]=0
}

m=gets.to_i
(1..m).map{
  a,b,c=gets.split.map(&:to_i)
  d[a][b]=d[b][a]=c
}

(0...n).map{|k|
  (0...n).map{|i|
    (0...n).map{|j|
      d[i][j] = [ d[i][j], d[i][k] + d[k][j] ].min
    }}}

ans = 1e13.to_i

(1..(n-2)).map{|i|
  (1..(n-2)).map{|j|
    if i != j
      r = d[0][i] + d[i][j] + d[j][n-1]
      r += stay[i] + stay[j]
      ans = [ans, r].min
    end
  }
}

p ans
0