結果

問題 No.807 umg tours
ユーザー 👑 obakyan
提出日時 2019-04-28 21:27:02
言語 Lua
(LuaJit 2.1.1734355927)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 60,384 KB
最終ジャッジ日時 2024-12-17 23:58:39
合計ジャッジ時間 17,159 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 14 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

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