import os import sys import fileinput import heapq def main(file): N, M = map(int, file.readline().strip().split(' ')) e=[[] for i in range(2 * N)] for i in range(M): v1, v2, cost = [int(x) for x in file.readline().strip().split(' ')] e[v1-1].append((v2-1,cost)) e[v2-1].append((v1-1,cost)) e[v1-1 + N].append((v2-1 + N,cost)) e[v2-1 + N].append((v1-1 + N,cost)) e[v1-1].append((v2-1 + N,0)) e[v2-1].append((v1-1 + N,0)) d = [10**9 + 1] * (2*N) d[0] = 0 h = [] heapq.heappush(h, (0,0)) heapq.heappush(h, (0,N)) while h: c, j = heapq.heappop(h) if d[j]