import sys from typing import Union input=sys.stdin.readline n,m=map(int,input().split()) abc=[list(map(int,input().split())) for _ in range(m)] g=[[] for _ in range(n)] for a,b,c in abc: a,b=a-1,b-1 g[a].append([b,c]) g[b].append([a,c]) """ ダイクストラ seen[v]:0にできる権利を使っていない場合のvまでの最短距離 seen[v+n]:0にできる権利を使った場合のvまでの最短距離 """ inf=10**18 seen=[inf]*(2*n) seen[0]=0 seen[0+n]=0 todo=[[0,0]] from heapq import heappop,heappush while todo: d,v=heappop(todo) if seen[v]seen[v]+nd: seen[nv]=seen[v]+nd heappush(todo,[seen[nv],nv]) if seen[nv+n]>seen[v]: seen[nv+n]=seen[v] heappush(todo,[seen[nv+n],nv+n]) else: if seen[nv+n]>seen[v]+nd: seen[nv+n]=seen[v]+nd heappush(todo,[seen[nv+n],nv+n]) for v in range(n): print(seen[v]+seen[v+n])