結果

問題 No.160 最短経路のうち辞書順最小
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2015-03-02 00:27:08
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 11,524 KB
実行使用メモリ 19,648 KB
最終ジャッジ日時 2023-09-06 06:12:21
合計ジャッジ時間 26,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,300 KB
testcase_01 AC 81 ms
14,992 KB
testcase_02 AC 81 ms
15,200 KB
testcase_03 WA -
testcase_04 AC 1,967 ms
19,132 KB
testcase_05 WA -
testcase_06 AC 1,972 ms
19,204 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M, S, G = gets.split.map(&:to_i)
INF=99999
ma = Array.new(N).map{Array.new(N,INF)}
ro = Array.new(N).map{Array.new(N,[INF])}
(0...M).each{|m|
    a, b, c = gets.split.map(&:to_i)
    ma[a][b]=c
    ro[a][b]=[a]
    ma[b][a]=c
    ro[b][a]=[b]
}
(0...N).each{|i|
    (0...N).each{|j|
        (0...N).each{|k|
=begin
                    if i==5 && j==6 then
                        puts
                        puts "ma[#{i}][#{j}]=#{ma[i][j]}, ro[#{i}][#{j}]=#{ro[i][j].join(' ')}"
                        puts "ma[#{i}][#{k}]=#{ma[i][k]}, ro[#{i}][#{k}]=#{ro[i][k].join(' ')}"
                        puts "ma[#{k}][#{j}]=#{ma[k][j]}, ro[#{k}][#{j}]=#{ro[k][j].join(' ')}"
                    end
=end
            if (ma[i][k] + ma[k][j] < ma[i][j])  ||
                (ma[i][j]==ma[i][k] + ma[k][j] && (ro[i][k]+ro[k][j]).join("")<ro[i][j].join("")) then
                    ma[i][j] = ma[i][k]+ma[k][j]
                    ro[i][j] = ro[i][k]+ro[k][j]
            end
        }
    }
}
puts ro[S][G].join(" ") + " " + G.to_s
0