結果

問題 No.1601 With Animals into Institute
ユーザー 小野寺健小野寺健
提出日時 2021-11-16 15:39:14
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,598 ms / 3,000 ms
コード長 574 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2023-08-22 15:42:30
合計ジャッジ時間 37,472 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,124 KB
testcase_01 AC 80 ms
15,032 KB
testcase_02 AC 80 ms
15,208 KB
testcase_03 AC 110 ms
15,776 KB
testcase_04 AC 110 ms
15,896 KB
testcase_05 AC 111 ms
15,764 KB
testcase_06 AC 2,483 ms
77,184 KB
testcase_07 AC 2,217 ms
76,748 KB
testcase_08 AC 2,562 ms
76,652 KB
testcase_09 AC 2,400 ms
74,952 KB
testcase_10 AC 2,504 ms
75,844 KB
testcase_11 AC 2,466 ms
74,692 KB
testcase_12 AC 2,527 ms
76,404 KB
testcase_13 AC 2,409 ms
76,480 KB
testcase_14 AC 2,390 ms
75,800 KB
testcase_15 AC 2,389 ms
74,500 KB
testcase_16 AC 2,401 ms
75,276 KB
testcase_17 AC 2,598 ms
75,280 KB
testcase_18 AC 108 ms
15,768 KB
testcase_19 AC 112 ms
15,784 KB
testcase_20 AC 111 ms
15,924 KB
testcase_21 AC 111 ms
15,860 KB
testcase_22 AC 111 ms
16,024 KB
testcase_23 AC 108 ms
15,880 KB
testcase_24 AC 110 ms
15,752 KB
testcase_25 AC 109 ms
15,800 KB
testcase_26 AC 110 ms
15,916 KB
testcase_27 AC 80 ms
15,028 KB
testcase_28 AC 82 ms
15,132 KB
testcase_29 AC 81 ms
15,124 KB
testcase_30 AC 79 ms
15,204 KB
testcase_31 AC 79 ms
15,132 KB
testcase_32 AC 79 ms
15,032 KB
testcase_33 AC 80 ms
15,148 KB
testcase_34 AC 79 ms
15,036 KB
testcase_35 AC 80 ms
15,136 KB
testcase_36 AC 79 ms
15,136 KB
testcase_37 AC 80 ms
15,068 KB
testcase_38 AC 78 ms
15,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split(" ").map{|s| s.to_i}

cost = Array.new(N) {Array.new}

M.times {
	a, b, c, x = gets.split(" ").map{|s| s.to_i}
	cost[a-1] << [b-1, c, x]
	cost[b-1] << [a-1, c, x]
}

d = Array.new(N) {Array.new(2, Float::INFINITY)}

d[N-1][0] = 0

q = [[N-1, 0]]

while q.length > 0 do
	v, x = q.shift
	cost[v].each {|nv, c, nx|
		if nx == 0 then
			if d[nv][x] > d[v][x] + c then
				d[nv][x] = d[v][x] + c
				q << [nv, x]
			end
		else
			if d[nv][nx] > d[v][x] + c then
				d[nv][nx] = d[v][x] + c
				q << [nv, nx]
			end
		end
	}
end

0.upto(N-2) {|i|
	puts d[i][1]
}
0