import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class Dijkstra: def __init__(self, N, E, inf=1 << 50): self.N = N self.E = E self.inf = inf def cost_from(self, s): C = [self.inf] * self.N C[2 * s] = 0 C[2 * s + 1] = 0 h = [(0, 2 * s)] visited = set() while len(h) > 0: _, v = heapq.heappop(h) if v in visited: continue visited.add(v) for c, d in self.E[v]: if C[d] > C[v] + c: C[d] = C[v] + c heapq.heappush(h, (C[d], d)) return C N, M = map(int, input().split()) E = [[] for _ in range(2 * N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 a1, a0 = 2 * a, 2 * a + 1 b1, b0 = 2 * b, 2 * b + 1 E[a1].append((c, b1)) E[a1].append((0, b0)) E[a0].append((c, b0)) E[b1].append((c, a1)) E[b1].append((0, a0)) E[b0].append((c, a0)) solver = Dijkstra(2 * N, E) C = solver.cost_from(0) for i in range(N): print(C[2 * i] + C[2 * i + 1])