import sys
from heapq import heapify,heappop,heappush
input=sys.stdin.readline
write=sys.stdout.write

N,M=map(int,input().split())
E=[[] for _ in range(2*N+1)]

for _ in range(M):
    a,b,c=map(int,input().split())
    E[a].append((b,c))
    E[a].append((b+N,c))
    E[a+N].append((b+N,c))

    E[b].append((a,c))
    E[b].append((a+N,c))
    E[b+N].append((a+N,c))

inf=float("inf")
T=[inf]*(2*N+1)
T[1]=0

S=set()

Q=[(0,1)]

while Q and len(S)<2*N:
    d,x=heappop(Q)
    if x in S:
        continue

    S.add(x)
    for y,c in E[x]:
        if x<=N and N<y:
            c=0

        if T[y]>d+c:
            T[y]=d+c
            heappush(Q,(d+c,y))

X=[T[x]+T[x+N] if x!=1 else 0 for x in range(1,N+1)]
write("\n".join(map(str,X)))