from numpy import*
from scipy.sparse import*
from sys import stdin
n,m=map(int,stdin.readline().split())
e=[]
for i in range(m):
    a,b,c=map(int,stdin.readline().split())
    for _ in [0,0]:
        e.append([a,b,c])
        e.append([a,b+n,0])
        e.append([a+n,b+n,c])
        a,b=b,a
edge=array(e,int64).T
graph=csr_matrix((edge[2],edge[:2]-1),(n+n,n+n))
dist=csgraph.dijkstra(graph,True,0)
for i in range(n):
    print(int(dist[i]+min(dist[i],dist[i+n])))