import heapq INF = 10**18 def dijkstra(s, edge): n = len(edge) dist = [INF]*n dist[s] = 0 edgelist = [] heapq.heappush(edgelist,(dist[s], s)) while edgelist: minedge = heapq.heappop(edgelist) if dist[minedge[1]] < minedge[0]: continue v = minedge[1] for e in edge[v]: if dist[e[1]] > dist[v]+e[0]: dist[e[1]] = dist[v]+e[0] heapq.heappush(edgelist,(dist[e[1]], e[1])) return dist import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) G = [[] for i in range(2*n)] for i in range(m): a, b,c = map(int, input().split()) a, b = a-1, b-1 G[a].append((c, b)) G[b].append((c, a)) G[a].append((0, b+n)) G[b].append((0, a+n)) G[a+n].append((c, b+n)) G[b+n].append((c, a+n)) for i in range(n): G[i].append((0, i+n)) dist = dijkstra(0, G) for i in range(n): ans = dist[i]+dist[i+n] print(ans)