N, M = map(int, input().split())
A, B, C = zip(*(map(int, input().split()) for _ in range(M)))

inf = 1 << 60
cur: list[int] = [inf for _ in range(N)]
fix: list[bool] = [False for _ in range(N)]
cur[0] = 0

G: list[list[tuple[int, int]]] = [[] for _ in range(N)]
for i in range(M):
    G[A[i] - 1].append((B[i] - 1, C[i]))
    G[B[i] - 1].append((A[i] - 1, C[i]))

while True:
    pos = -1
    mdist = inf
    for i in range(N):
        if fix[i]:
            continue
        if cur[i] < mdist:
            pos = i
            mdist = cur[i]
    if pos < 0:
        break
    fix[pos] = True
    for np in G[pos]:
        nx, nl = np
        cur[nx] = min(cur[nx], cur[pos] + nl)

print(cur)
