import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 # md = 998244353 md = 10**9+7 from heapq import * n, m = MI() to = [[] for _ in range(n)] for _ in range(m): u, v, c = MI1() to[u].append((v, c+1)) to[v].append((u, c+1)) dist = [inf]*n*2 dist[0] = 0 dist[1] = 0 hp = [(0, 0)] while hp: d, u = heappop(hp) u, f = divmod(u, 2) for v, c in to[u]: nd, nv = d+c, v*2+f if nd < dist[nv]: dist[nv] = nd heappush(hp, (nd, nv)) if f == 0: nd, nv = d, v*2+1 if nd < dist[nv]: dist[nv] = nd heappush(hp, (nd, nv)) for u in range(n): print(dist[u*2]+dist[u*2+1])