def main(): from heapq import heappop, heappush from sys import stdin n,m = map(int,input().split()) abcs = [[] for i in range(n)] for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 abcs[a].append([b,c]) abcs[b].append([a,c]) INF = 10**14 dp = [[INF]*2 for i in range(n)] dp[0][0] = 0 dp[0][1] = 0 q = [(0, 0, 0)]#c, idx, use while q: c, j, use = heappop(q) abc = abcs[j] if dp[j][use] != c: continue for k in range(len(abc)): j1,c1 = abc[k] ndis = c1 + c if use == 0: if dp[j1][0] > ndis: dp[j1][0] = ndis heappush(q, (ndis, j1, 0)) if dp[j1][1] > c: dp[j1][1] = c heappush(q, (c, j1, 1)) else: if dp[j1][1] > ndis: dp[j1][1] = ndis heappush(q, (ndis, j1, 1)) def dijkstra(s, n): # (始点, ノード数) dist = [INF] * n hq = [(0, s)] # (distance, node) dist[s] = 0 seen = [False] * n # ノードが確定済みかどうか while hq: tmp = heappop(hq) # ノードを pop する v = tmp[1] c = tmp[0] seen[v] = True if dist[v] < c: continue for to, cost in abcs[v]: # ノード v に隣接しているノードに対して if seen[to] == False and dist[v] + cost < dist[to]: dist[to] = dist[v] + cost heappush(hq, (dist[to], to)) return dist fst = dijkstra(0,n) print(0) for i in range(1,n): print(fst[i]+dp[i][1]) main()