import sys,collections,heapq def MI(): return map(int,sys.stdin.readline().rstrip().split()) class Dijkstra: def __init__(self): self.e = collections.defaultdict(list) def add(self, u, v, d, directed=False): if directed is False: # 無向グラフの場合 self.e[u].append([v, d]) self.e[v].append([u, d]) else: # 有向グラフの場合 self.e[u].append([v, d]) def delete(self, u, v): self.e[u] = [_ for _ in self.e[u] if _[0] != v] self.e[v] = [_ for _ in self.e[v] if _[0] != u] def search(self, s): # sから各頂点までの最短距離 d = collections.defaultdict(lambda: float('inf')) d[s] = 0 q = [] heapq.heappush(q, (0, s)) v = collections.defaultdict(bool) while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True for uv, ud in self.e[u]: if v[uv]: continue vd = k + ud if d[uv] > vd: d[uv] = vd heapq.heappush(q, (vd, uv)) return d N,M = MI() Di = Dijkstra() for _ in range(M): a,b,c = MI() Di.add((a,0),(b,0),c,directed=False) Di.add((a,1),(b,1),c,directed=False) Di.add((a,0),(b,1),0,directed=True) Di.add((b,0),(a,1),c,directed=True) dist = Di.search((1,0)) for i in range(1,N+1): print(dist[(i,0)]+dist[(i,1)] if i != 1 else 0)