from heapq import heappop, heappush import sys input = sys.stdin.readline def solve() : N, M = map(int, input().split()) edge = [[] for i in range(N)] for i in range(M): a, b, c = map(int, input().split()) a-=1 b-=1 edge[a].append((c, b)) edge[b].append((c, a)) dist=[[float('inf'),float('inf')]for i in range(N)] dist[0]=[0,0] pq = [] heappush(pq, (0,0,0)) heappush(pq, (0,1,0)) while pq: d, num, cur = heappop(pq) if d > dist[cur][num]: continue for cost, to in edge[cur]: ret = d+cost if dist[to][num]>ret : dist[to][num]=ret heappush(pq, (ret,num,to)) if num == 0 : if dist[to][1]>d : dist[to][1]=d heappush(pq, (d,1,to)) for x,y in dist : print(x+y) solve()