from heapq import heappop, heappush

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
C = dict()
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1
    graph[a].append((b, c))
    graph[b].append((a, c))
    C[a, b] = C[b, a] = c

INF = 10**18
D = [INF] * 2*N
hq = [(0, 0), (0, N)]
while hq:
    d, node = heappop(hq)
    if D[node] != INF:
        continue
    D[node] = d
    if node >= N:
        n = node - N
        for nex, c in graph[n]:
            if D[nex+N] == INF:
                heappush(hq, (d+c, nex+N))
    else:
        for nex, c in graph[node]:
            if D[nex] == INF:
                heappush(hq, (d+c, nex))
            if D[nex+N] == INF:
                heappush(hq, (d, nex+N))

ans = [D[i]+D[i+N] for i in range(N)]
print(*ans, sep='\n')