import sys import heapq def main(): input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 adj = [[] for _ in range(N + 1)] for _ in range(M): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 c = int(input[ptr]) ptr += 1 adj[a].append((b, c)) adj[b].append((a, c)) # Initialize distances INF = float('inf') d0 = [INF] * (N + 1) d0[1] = 0 d1 = [INF] * (N + 1) heap = [] heapq.heappush(heap, (0, 1, 0)) # (distance, node, state) while heap: dist, u, s = heapq.heappop(heap) if s == 0 and dist > d0[u]: continue if s == 1 and dist > d1[u]: continue for v, c in adj[u]: if s == 0: # Not using ticket new_dist = dist + c if new_dist < d0[v]: d0[v] = new_dist heapq.heappush(heap, (new_dist, v, 0)) # Using ticket new_dist = dist + 0 if new_dist < d1[v]: d1[v] = new_dist heapq.heappush(heap, (new_dist, v, 1)) else: # Using ticket already new_dist = dist + c if new_dist < d1[v]: d1[v] = new_dist heapq.heappush(heap, (new_dist, v, 1)) for i in range(1, N + 1): if d0[i] == INF: print(0) else: option1 = 2 * d0[i] option2 = d1[i] + d0[i] if d1[i] != INF else INF option3 = d0[i] + d1[i] if d1[i] != INF else INF min_option = min(option1, option2, option3) print(min_option) if __name__ == '__main__': main()