from collections import defaultdict from heapq import heappush, heappop INF = 1 << 60 N, M = map(int, input().split()) adj = defaultdict(list) for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 adj[a].append((b, c)) adj[b].append((a, c)) dists = [[INF] * 2 for _ in range(N)] q = [(0, 0, 0)] # (距離, チケット使用回数, 頂点) while q: d, cnt, v = heappop(q) if dists[v][cnt] <= d: continue dists[v][cnt] = d # チケットを使う if cnt == 0: for to, _ in adj[v]: if dists[to][1] <= d: continue heappush(q, (d, 1, to)) # チケットを使わない for to, cost in adj[v]: if dists[to][cnt] <= d+cost: continue heappush(q, (d+cost, cnt, to)) dists[0][0] = dists[0][1] = 0 for i in range(N): ans = dists[i][0] + dists[i][1] print(ans)