N,M = map(int,input().split()) ABC = [list(map(int,input().split())) for _ in range(M)] E = [[] for _ in range(N)] for a,b,c in ABC: E[a-1].append([b-1,c]) E[b-1].append([a-1,c]) dp1 = [10**18] * N dp2 = [10**18] * N dp1[0] = 0 dp2[0] = 0 def dfs1(x,maxc,cost,path): for to,c in E[x]: if to in path: continue else: maxct = max(maxc,c) costt = cost + c dp1[to] = min(dp1[to],costt - maxct) dfs1(to,maxct,costt,path | {to}) def dfs2(x,cost,path): for to,c in E[x]: if to in path: continue else: costt = cost + c dp2[to] = min(dp2[to],costt) dfs2(to,costt,path | {to}) dfs1(0,0,0,{0}) dfs2(0,0,{0}) for i in range(N): print(dp1[i]+dp2[i])