from heapq import heappush, heappop INF = float('inf') N, M = map(int, input().split()) adj = [[] for _ in range(N)] for i in range(M): s, t, d = map(int, input().split()) s -= 1 t -= 1 adj[s].append((t, d)) adj[t].append((s, d)) def dijkstra(s, n): dist = [INF] * n hq = [(0, s)] dist[s] = 0 seen = [False] * n # 経路復元用 # prev = [-1]*n while hq: v = heappop(hq)[1] seen[v] = True for to, cost in adj[v]: if seen[to] == False and dist[v] + cost < dist[to]: dist[to] = dist[v] + cost # prev[to] = v heappush(hq, (dist[to], to)) return dist d = dijkstra(0, N) print(0) for i in range(1,N): res = float('inf') for b, c in adj[i]: res = min(res, d[b], c) print(res+d[i])