import sys from heapq import heappop, heappush input = sys.stdin.readline N, M = map(int, input().split()) ABC = [list(map(int, input().split())) for _ in range(M)] G = [[] for _ in range(N)] for i in range(M): a, b, c = ABC[i] a -= 1 b -= 1 G[a].append([b, c]) G[b].append([a, c]) dist = [[float('inf')]*2 for _ in range(N)] dist[0][0] = 0 # dijkstra que = [] heappush(que, (0, 0, 0)) while que: cost, now, used = heappop(que) if dist[now][used] < cost: continue for nxt, d in G[now]: new_cost = dist[now][used] + d if dist[nxt][used] > new_cost: dist[nxt][used] = new_cost heappush(que, (new_cost, nxt, used)) if used == 0 and dist[nxt][1] > dist[now][0]: dist[nxt][1] = dist[now][0] heappush(que, (dist[nxt][1], nxt, 1)) print(0) for i in range(1, N): print(dist[i][0] + dist[i][1])