import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict from heapq import heappop, heappush con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b, w): self.graph[a].append((b, w)) class Dijkstra(object): def __init__(self, graph, s): self.g = graph.graph self.dist = defaultdict(lambda: INF); self.dist[s] = 0 self.prev = defaultdict(lambda: None) self.Q = [] heappush(self.Q, (self.dist[s], s)) while self.Q: dist_u, u = heappop(self.Q) if self.dist[u] < dist_u: continue for v, w in self.g[u]: alt = dist_u + w if self.dist[v] > alt: self.dist[v] = alt self.prev[v] = u heappush(self.Q, (alt, v)) #処理内容 def main(): N, M = getlist() G = Graph() for i in range(M): a, b, w = getlist() a -= 1; b -= 1 G.add_edge(a, b, w) G.add_edge(b, a, w) G.add_edge(a, b + N, 0) G.add_edge(b, a + N, 0) G.add_edge(a + N, b + N, w) G.add_edge(b + N, a + N, w) D = Dijkstra(G, 0) print(0) for i in range(1, N): print(D.dist[i] + D.dist[i + N]) if __name__ == '__main__': main()