import sys from heapq import heappush, heappop INF = 10 ** 14 + 1 def dijkstra(N, G, s): """https://tjkendev.github.io/procon-library/python/graph/dijkstra.html から拝借しています。""" dist = [INF] * N que = [(0, s)] dist[s] = 0 while que: c, v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + cost < dist[t]: dist[t] = dist[v] + cost heappush(que, (dist[t], t)) return dist input = sys.stdin.buffer.readline N, M = map(int, input().split()) G = [[] for _ in range(2 ** N)] for i in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, c)) G[b].append((a, c)) G[a + N].append((b + N, c)) G[b + N].append((a + N, c)) G[a].append((b + N, 0)) G[b].append((a + N, 0)) dist = dijkstra(2 * N, G, 0) ans = [dist[i] + dist[i + N] for i in range(N)] ans[0] = 0 print(*ans, sep='\n')