from heapq import heappop, heappush import sys input=sys.stdin.readline n, m = map(int, input().split()) edge = [[] for _ in range(2*n)] for i in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 edge[a].append((c, b)) edge[b].append((c, a)) edge[a+n].append((c, b+n)) edge[b+n].append((c, a+n)) edge[a].append((0, b+n)) edge[b].append((0, a+n)) dist = [float("inf")]*(2*n) dist[0] = dist[n] = 0 pq = [] heappush(pq, (0, 0)) heappush(pq, (0, n)) while pq: d, cur = heappop(pq) if d > dist[cur]: continue for cost, to in edge[cur]: if dist[to] > d + cost: dist[to] = d + cost heappush(pq, (d+cost, to)) for i in range(n): print(dist[i]+dist[i+n])