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 = {} straight[1], warp[1] = 0, 0 for i = 2, n do straight[i], warp[i] = inf, inf end local cue = {} cue[1] = 1 local done, tasks = 0, 1 local mmi = math.min while(done < tasks) do done = done + 1 local src = cue[done] for k, v in pairs(costs[src]) do local added = false if(straight[src] + v < straight[k]) then straight[k] = straight[src] + v added = true tasks = tasks + 1 table.insert(cue, k) end local w = mmi(warp[src] + v, straight[src]) if(w < warp[k]) then warp[k] = w if(not added) then tasks = tasks + 1 table.insert(cue, k) end end end end for i = 1, n do print(straight[i] + warp[i]) end