import sys from heapq import heapify,heappush,heappop input = sys.stdin.readline INF = 10 ** 16 n,m = map(int,input().split()) G = [[] for _ in range(n)] for _ in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 G[a].append((b,c)) G[b].append((a,c)) dist = [INF] * n dist[0] = 0 q = [(0,0)] heapify(q) while q: d,v = heappop(q) if dist[v] < d: continue for e,cost in G[v]: if dist[e] > dist[v] + cost: dist[e] = dist[v] + cost heappush(q,(dist[e],e)) dist1 = [INF] * n dist1[0] = 0 heappush(q,(0,0)) while q: d,v = heappop(q) if dist1[v] < d: continue for e,cost in G[v]: m = min(dist[v],dist1[v] + cost) if dist1[e] > m: dist1[e] = m heappush(q,(dist1[e],e)) print('\n'.join(map(str,[dist[i] + dist1[i] for i in range(n)])))