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, 0)] cost = [[None, None] for _ in range(n)] cost[0][1] = 0 while q: c, f, x = heapq.heappop(q) if cost[x][f] is not None: continue cost[x][f] = c for y, cn in e[x]: if cost[y][f] is None: heapq.heappush(q, (c+cn, f, y)) if not f and cost[y][1] is None: heapq.heappush(q, (c, 1, y)) for i in range(n): sys.stdout.write(f"{sum(cost[i])}\n")