# 一回だけコスト0で移動できるダイクストラで、各頂点への距離を「権利使った,使ってない」の二通りで求める N,M = map(int,input().split()) G = [[] for i in range(N)] for _ in range(M): a,b,c = map(int,input().split()) G[a - 1].append([b - 1, c]) G[b - 1].append([a - 1, c]) INF = 1 << 60 dist = [[INF] * 2 for i in range(N)] import heapq as hq q = [] hq.heappush(q, (0, 0, False)) dist[0][True] = 0 while q: d,v,used = hq.heappop(q) # print("v",v,"d",d,"used",used) if dist[v][used] != INF: continue dist[v][used] = d for child, c in G[v]: # print(child,c,"used",used) # 権利を使える場合 if not used: if dist[child][True] == INF: # print("権利を使って",v,"から",child,"に移動") hq.heappush(q, (d, child, True)) # 権利を使わない場合 if dist[child][used] == INF: # print("権利を遣わず",v,"から",child,"に移動",used) hq.heappush(q, (d + c, child, used)) #print(dist) for i in range(N): print(dist[i][False] + dist[i][True])