結果

問題 No.160 最短経路のうち辞書順最小
ユーザー gigurururugigurururu
提出日時 2015-03-03 12:19:02
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,435 ms / 5,000 ms
コード長 352 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 11,376 KB
実行使用メモリ 45,152 KB
最終ジャッジ日時 2023-08-27 05:30:11
合計ジャッジ時間 5,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,104 KB
testcase_01 AC 85 ms
14,988 KB
testcase_02 AC 83 ms
15,056 KB
testcase_03 AC 85 ms
15,100 KB
testcase_04 AC 107 ms
15,536 KB
testcase_05 AC 172 ms
16,920 KB
testcase_06 AC 166 ms
16,440 KB
testcase_07 AC 105 ms
16,044 KB
testcase_08 AC 106 ms
16,136 KB
testcase_09 AC 100 ms
15,944 KB
testcase_10 AC 109 ms
16,292 KB
testcase_11 AC 105 ms
16,080 KB
testcase_12 AC 102 ms
15,956 KB
testcase_13 AC 105 ms
16,328 KB
testcase_14 AC 100 ms
15,724 KB
testcase_15 AC 101 ms
16,276 KB
testcase_16 AC 100 ms
16,212 KB
testcase_17 AC 108 ms
15,908 KB
testcase_18 AC 102 ms
15,920 KB
testcase_19 AC 104 ms
16,280 KB
testcase_20 AC 102 ms
16,176 KB
testcase_21 AC 107 ms
15,916 KB
testcase_22 AC 103 ms
15,784 KB
testcase_23 AC 105 ms
15,592 KB
testcase_24 AC 111 ms
16,304 KB
testcase_25 AC 101 ms
15,828 KB
testcase_26 AC 107 ms
16,424 KB
testcase_27 AC 94 ms
15,468 KB
testcase_28 AC 1,435 ms
45,152 KB
testcase_29 AC 93 ms
15,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def g;gets.split.map(&:to_i)end
N,M,S,G=g
L=(0...N).map{[]}
M.times{
  a,b,c=g
  L[a][b]=L[b][a]=c
}
q=[[0,[S]],[1e9]]
gn={}
while q[0]
  e,n=q.shift
  next if gn[n[-1]]
  gn[n[-1]]=e
  break if n[-1]==G
  L[n[-1]].each.with_index{|i,j|
    i&&(
      nxt=[i+e,n+[j]]
      q.insert((0...q.size).bsearch{|k|(q[k]<=>nxt)>0},nxt)
    )
  }
end
puts n*" "
0