N,M = map(int, input().split()) E = [[] for _ in range(N)] for _ in range(M): a,b,c = map(int, input().split()) a -= 1 b -= 1 E[a].append(c*N+b) E[b].append(c*N+a) import heapq inf = 10**15 d1 = [inf]*N d2 = [inf]*N used1 = [0]*N used2 = [0]*N h1 = [0] while h1: temp = heapq.heappop(h1) u = temp%N dist = temp//N if used1[u]: continue d1[u] = dist used1[u] = 1 for e in E[u]: r = e//N v = e%N if used1[v]: continue heapq.heappush(h1, (r+dist)*N+v) h2 = [] used2[0] = 1 d2[0] = 0 for e in E[0]: heapq.heappush(h2, (0, e//N, e%N)) while h2: temp = heapq.heappop(h2) u = temp[2] dist = temp[0] len = temp[1] if used2[u]: continue d2[u] = dist used2[u] = 1 for e in E[u]: r = e//N v = e%N if len >= r: heapq.heappush(h2, (dist+r, len, v)) else: heapq.heappush(h2, (dist+len, r, v)) for i in range(N): print(d1[i]+d2[i])