import sys readline = sys.stdin.readline N,M = map(int,readline().split()) G = [[] for i in range(2 * N)] for _ in range(M): a,b,c = map(int,readline().split()) a -= 1 b -= 1 G[a].append([b, c]) G[b].append([a, c]) G[a].append([b + N, 0]) G[b].append([a + N, 0]) G[a + N].append([b + N, c]) G[b + N].append([a + N, c]) INF = 1 << 60 dist = [0] * (2 * N) best = [INF] * (2 * N) visited = [False] * (2 * N) import heapq as hq q = [] hq.heappush(q, (0, 0)) while q: d,v = hq.heappop(q) if visited[v]: continue visited[v] = True dist[v] = d for child, cost in G[v]: if visited[child]: continue if best[child] <= d + cost: continue best[child] = d + cost hq.heappush(q, (d + cost, child)) print(0) for i in range(1, N): print(dist[i] + dist[i + N])