from collections import defaultdict from collections import deque N, M = map( int, input().split()) E = [ [] for _ in range(N)] D = defaultdict( int) for _ in range(M): a, b, c = map( int, input().split()) a, b = a-1, b-1 D[(a,b)] = D[(b,a)] = c E[a].append(b) E[b].append(a) V = [ [10**16, 10**16,0] for _ in range(N)] V[0] = [0,0,0] H = deque(E[0]) P = [0]*N P[0] = 1 for t in E[0]: d = D[(0,t)] V[t] = [d,d,d] P[t] = 1 while H: h = H.popleft() q, p, m = V[h] for t in E[h]: d = D[(h,t)] V[t][0] = min(V[t][0], q + d) if V[t][1] - V[t][2] >= p + d - max(d,m): V[t][1] = p+d V[t][2] = max(d,m) if P[t] == 0: H.append(t) P[t] = 1 for i in range(N): print(V[i][0] + V[i][1] - V[i][2])