from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) e = [[] for _ in range(2*N)] for _ in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 e[a].append((b,c)) e[a].append((b+N,0)) e[b].append((a,c)) e[b].append((a+N,0)) e[b+N].append((a+N,c)) e[a+N].append((b+N,c)) INF = (1<<60) def dijkstra(s,e): N = len(e) dist = [INF]*N dist[s]=0 h = [] heappush(h,s) while h: nw,v = divmod(heappop(h),N) if dist[v]!=nw: continue for iv,ic in e[v]: nc = ic + nw if nc < dist[iv]: dist[iv] = nc heappush(h,nc*N + iv) return dist D = dijkstra(0,e) for i in range(N): print(min(D[i]+D[i+N],2*D[i])) # print(D[i],D[i+N])