from heapq import heappush, heappop INF = float('inf') N, M = map(int, input().split()) adj = [[] for _ in range(N)] for i in range(M): s, t, d = map(int, input().split()) s -= 1 t -= 1 adj[s].append((t, d)) adj[t].append((s, d)) def dijkstra(s, n): dist = [[INF] * 2 for _ in range(N)] hq = [(0, 0, s)] dist[s][0] = 0 dist[s][1] = 0 while hq: d, ticket, v = heappop(hq) if d > dist[v][ticket]: continue for to, cost in adj[v]: if dist[v][ticket] + cost < dist[to][ticket]: dist[to][ticket] = d + cost # prev[to] = v heappush(hq, (dist[to][ticket], ticket, to)) if ticket == 0: if dist[to][1] > d: dist[to][1] = d heappush(hq, (d, 1, to)) return dist dis = dijkstra(0, N) for a, b in dis: print(a+b)