import heapq N,M = map(int,input().split()) lsg = [[] for i in range(N)] for i in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 lsg[a].append((b,c)) lsg[b].append((a,c)) h = [(0,0,0)] INF = float('INF') cost0 = [INF]*(N) cost1 = [INF]*(N) cost0[0] = 0 cost1[0] = 0 used0 = [False]*(N) used1 = [False]*(N) while h: c,n,f = heapq.heappop(h) if used0[n] and used1[n]: continue if f == 0: used0[n] = True if f == 1: used1[n] = True for nex,cos in lsg[n]: if f == 0: # 使える if used0[nex]==False: if cost0[nex] > c + cos: # 使わない cost0[nex] = c + cos heapq.heappush(h, (c+cos,nex,0)) if used1[nex]==False: if cost1[nex] > c: # 使う cost1[nex] = c heapq.heappush(h, (c,nex,1)) if f == 1: # 使えない if used1[nex]==False: if cost1[nex] > c+ cos: cost1[nex] = c+ cos heapq.heappush(h, (c+ cos,nex,1)) for i in range(N): print(cost0[i]+cost1[i])