from heapq import * n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges[a].append((b, c)) edges[b].append((a, c)) inf = 1 << 30 dist = [[inf] * 2 for _ in range(n)] dist[0][0] = 0 dist[0][1] = 0 hq = [(0, 0, 0)] while hq: d, pos, t = heappop(hq) if d > dist[pos][t]: continue for npos, c in edges[pos]: if dist[npos][t] > d + c: dist[npos][t] = d + c heappush(hq, (d + c, npos, t)) if t == 0: if dist[npos][1] > d : dist[npos][1] = d heappush(hq, (d, npos, 1)) for d1, d2 in dist: print(d1 + d2)