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, used, x = heapq.heappop(q) if cost[x][used] is not None: continue cost[x][used] = c for y, cn in e[x]: heapq.heappush(q, (c+cn, used, y)) if not used: heapq.heappush(q, (c, 1, y)) for i in range(n): print(sum(cost[i]))