結果

問題 No.807 umg tours
ユーザー 👑 obakyanobakyan
提出日時 2019-04-28 21:27:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 154,716 KB
最終ジャッジ日時 2023-08-22 21:40:31
合計ジャッジ時間 22,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 3 ms
4,504 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,504 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 256 ms
18,116 KB
testcase_21 AC 262 ms
18,476 KB
testcase_22 AC 107 ms
10,120 KB
testcase_23 AC 83 ms
8,884 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

ior = io.read
local n, m = ior("*n", "*n")
local costs = {}
for i = 1, n do costs[i] = {} end
for i = 1, m do
  local a, b, c = ior("*n", "*n", "*n")
  costs[a][b], costs[b][a] = c, c
end
local inf = 99999999999999
local straight = {}
local warp = {}
local searched = {}
straight[1], warp[1], searched[1] = 0, 0, true
for i = 2, n do straight[i], warp[i], searched[i] = inf, inf, false end
local cue = {}
cue[1] = 1
local done, tasks = 0, 1
local mmi = math.min
while(done < tasks) do
  done = done + 1
  local tgt = cue[done]
  searched[tgt] = true
  for k, v in pairs(costs[tgt]) do
    straight[k] = mmi(straight[k], straight[tgt] + v)
    warp[k] = mmi(warp[k], warp[tgt] + v)
    warp[k] = mmi(warp[k], straight[tgt])
    if(not searched[k]) then
      tasks = tasks + 1
      table.insert(cue, k)
    end
  end
end
for i = 1, n do
  print(straight[i] + warp[i])
end
0