import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**18 N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) dist = [[inf]*2 for _ in range(N)] dist[0][0] = 0 dist[0][1] = 0 que = [] heapq.heappush(que, (0, 0, 0)) # dist, node, used heapq.heappush(que, (0, 0, 1)) while que: ds, s, used = heapq.heappop(que) if dist[s][used] < ds: continue for t, dt in G[s]: if dist[t][used] > ds + dt: dist[t][used] = ds + dt heapq.heappush(que, (ds + dt, t, used)) if not used: if dist[t][used + 1] > ds: dist[t][used + 1] = ds heapq.heappush(que, (ds, t, used + 1)) for d in dist: print(sum(d))