import heapq import sys input = sys.stdin.readline n, m = map(int, input().split()) e = [[] for _ in range(n)] for _ in range(m): ai, bi, ci = map(int, input().split()) e[ai-1].append((bi-1, ci)) e[bi-1].append((ai-1, ci)) q = [(0, 0)] c1 = [None] * n while q: c, x = heapq.heappop(q) if c1[x] is not None: continue c1[x] = c for y, cn in e[x]: if c1[y] is not None: continue heapq.heappush(q, (c+cn, y)) q = [(0, 0, 0)] c2 = [None] * n while q: c, x, cut = heapq.heappop(q) if c2[x] is not None: continue c2[x] = (c, cut) for y, cn in e[x]: if c2[y] is not None: continue if cn > cut: heapq.heappush(q, (c+cut, y, cn)) else: heapq.heappush(q, (c+cn, y, cut)) for i in range(n): print(c1[i] + c2[i][0])