N,M = map(int,input().split()) G = [[] for _ in range(N + 1)] for _ in range(M): a,b,c = map(int,input().split()) G[a].append((b,c)) G[b].append((a,c)) import heapq C = 10 ** 16 dist = [C] * (N + 1) dist[1] = 0 q = [] heapq.heapify(q) heapq.heappush(q,(0,1)) while len(q): d,index = heapq.heappop(q) if d > dist[index]: continue for v,c in G[index]: if dist[v] > d + c: dist[v] = d + c heapq.heappush(q,(d+c,v)) dist2 = [C] * (N + 1) dist2[1] = 0 heapq.heappush(q,(0,1,False)) while len(q): d,index,flag = heapq.heappop(q) if flag and d > dist2[index]: continue for v,c in G[index]: if flag: if dist2[v] > dist2[index] + c: dist2[v] = dist2[index] + c heapq.heappush(q,(d + c,v,True)) else: if dist2[v] > dist[index]: dist2[v] = dist[index] heapq.heappush(q,(dist[index],v,True)) if dist[v] >= dist[index] + c: heapq.heappush(q,(dist[index] + c,v,False)) for i in range(N): print(dist[i+1] + dist2[i+1])