from heapq import heappush, heappop from collections import defaultdict import sys input = sys.stdin.readline def dijkstra(start): distance = [[10**18 for _ in range(2)] for _ in range(N+1)] distance[start][0] = 0 distance[start][1] = 0 priority_queue = [] heappush(priority_queue, (distance[start][0], start)) heappush(priority_queue, (distance[start][1], start)) while len(priority_queue) > 0: current_dist, current_node, state = heappop(priority_queue) if distance[current_node][state] < current_dist: continue if state == 0: for next_node, w in adj_dict[current_node]: if distance[next_node][0] > distance[current_node][0] + w: distance[next_node][0] = distance[current_node][0] + w heappush(priority_queue, (distance[next_node][0], next_node, 0)) if distance[next_node][1] > distance[current_node][0]: distance[next_node][1] = distance[current_node][0] heappush(priority_queue, (distance[next_node][1], next_node, 1)) else: for next_node, w in adj_dict[current_node]: if distance[next_node][1] > distance[current_node][1] + w: distance[next_node][1] = distance[current_node][1] + w heappush(priority_queue, (distance[next_node][1], next_node, 1)) return distance N, M = map(int, input().split()) adj_dict = defaultdict(list) for _ in range(M): a_i, b_i, c_i = map(int, input().split()) adj_dict[a_i].append((b_i, c_i)) adj_dict[b_i].append((a_i, c_i)) distance = dijkstra(1) for i in range(1, N+1): ans = distance[i][0] + distance[i][1] print(ans)