from heapq import heappop,heappush import sys input = sys.stdin.readline N,M=map(int,input().split()) table=[[] for i in range(2*N)] for i in range(M): a,b,c=map(int,input().split()) a,b=a-1,b-1 table[a].append((b,c)) table[b].append((a,c)) table[a].append((N+b,0)) table[b].append((N+a,0)) table[N+a].append((N+b,c)) table[N+b].append((N+a,c)) H=[] cost=[10**16]*(2*N) cost[0]=0 H.append((0,0)) while H: cos,pt=heappop(H) if cost[pt]cost[pt]+c: cost[y]=cost[pt]+c heappush(H,(cost[y],y)) print(0) for i in range(1,N): print(cost[i]+cost[N+i])