from heapq import heappop,heappush from collections import deque import sys input = sys.stdin.readline N,M=map(int,input().split()) table=[[] for i in range(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)) H=[] cost=[10**18]*N cost[0]=0 H.append((0,0)) while H: pt,cos=heappop(H) if cost[pt]cost[pt]+c: cost[y]=cost[pt]+c heappush(H,(y,cost[y])) dp=[10**19]*N dp[0]=0 def f(x): visit=[False]*N visit[x]=True H=deque() H.append(x) while H: z=H.popleft() for y,c in table[x]: if not visit[y]: dp[y]=min(dp[y],dp[x]+c,cost[x]) visit[y]=True H.append(y) return f(0) dp2=[10**19]*N dp2[0]=0 for x in range(N): for y,c in table[x]: dp2[x]=min(dp2[x],dp[y]+c) dp2[x]=min(dp2[x],cost[y]) for i in range(N): print(dp2[i]+cost[i])