結果

問題 No.160 最短経路のうち辞書順最小
ユーザー gigurururugigurururu
提出日時 2015-03-02 01:18:54
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 336 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 11,156 KB
実行使用メモリ 16,372 KB
最終ジャッジ日時 2023-09-06 06:14:29
合計ジャッジ時間 40,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
15,040 KB
testcase_01 AC 71 ms
15,276 KB
testcase_02 AC 70 ms
15,332 KB
testcase_03 WA -
testcase_04 AC 1,202 ms
16,304 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,549 ms
16,152 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1,505 ms
15,800 KB
testcase_28 AC 1,189 ms
15,968 KB
testcase_29 AC 1,441 ms
16,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def g;gets.split.map(&:to_i)end
N,M,S,G=g
L=(0...N).map{[1e9]*N}
d=L.map{[]}
N.times{|i|L[i][i]=0}
M.times{
  a,b,c=g
  L[a][b]=L[b][a]=c
  d[a][b]=d[b][a]=1
}
N.times{|k|N.times{|i|N.times{|j|L[i][j]=[L[i][j],L[i][k]+L[k][j]].min}}}
ans=[s=S]
while s!=G
  ans<<s=(0...N).find{|i|(L[s][i]+L[i][G]==L[s][G])&&d[s][i]==1}
end
puts ans*" "
0