import heapq N,M = map(int,input().split()) lsg = [[] for i in range(2*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)) lsg[a].append((b+N,0)) lsg[b].append((a+N,0)) lsg[a+N].append((b+N,c)) lsg[b+N].append((a+N,c)) h = [(0,0)] INF = float('INF') cost = [INF]*(2*N) cost[0] = 0 used = [False]*(2*N) while h: c,n = heapq.heappop(h) if used[n]: continue used[n] = True for nex,cos in lsg[n]: if used[nex]: continue if cost[nex] > c + cos: cost[nex] = c + cos heapq.heappush(h, (c+cos,nex)) for i in range(N): print(cost[i]+cost[i+N])