import sys input=lambda: sys.stdin.readline().rstrip() n,m=map(int,input().split()) nn=2*n edge=[[] for i in range(nn)] for i in range(m): a,b,c=map(int,input().split()) edge[a-1].append(c*10**6+b-1) edge[b-1].append(c*10**6+a-1) edge[a-1].append(b-1+n) edge[b-1].append(a-1+n) edge[a-1+n].append(c*10**6+b-1+n) edge[b-1+n].append(c*10**6+a-1+n) import heapq def dijkstra_heap(s): d=[float("inf")]*nn used=[True]*nn d[s]=0 used[s]=False edgelist=[] for e in edge[s]: heapq.heappush(edgelist,e) while edgelist: minedge=heapq.heappop(edgelist) minedge_cost=minedge//(10**6) minedge_v=minedge%(10**6) if not used[minedge_v]: continue d[minedge_v] = minedge_cost used[minedge_v] = False for e in edge[minedge_v]: e_cost=e//(10**6) e_v=e%(10**6) if used[e_v]: heapq.heappush(edgelist,e+minedge_cost*10**6) return d D=dijkstra_heap(0) for i in range(n): print(D[i]+min(D[n+i],D[i]))