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