from heapq import heappop, heappush N, M = map(int, input().split()) g = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 g[a].append((b, c)) g[b].append((a, c)) dist = [[1 << 60] * N for _ in range(3)] dist[0][0] = dist[1][0] = 0 hq = [] heappush(hq, (0, 0, 0)) heappush(hq, (0, 0, 1)) while hq: d, v, k = heappop(hq) if k == 2 or dist[k][v] < d: continue for nv, c in g[v]: if d + c < dist[k][nv]: dist[k][nv] = d + c heappush(hq, (d + c, nv, k)) if d < dist[k + 1][nv]: dist[k + 1][nv] = d heappush(hq, (d, nv, k + 1)) for i in range(N): print(dist[0][i] + dist[1][i])