from heapq import heappop, heappush

def dijkstra(start, dist, path):
  candidate = [(0, start)]
 
  while candidate:
    cost, i = heappop(candidate)
    if cost > dist[i]: continue
 
    for c, j in path[i]:
      if cost+c >= dist[j]: continue
      dist[j] = cost+c
      heappush(candidate, (cost+c, j))

def dijkstra2(start, dist, path):
  candidate = [(0, start, 0)]
 
  while candidate:
    cost, i, k = heappop(candidate)
    if cost > dist[i]: continue
 
    for c, j in path[i]:
      if k == 0:
        if cost >= dist[j + n]: continue
        dist[j + n] = cost
        heappush(candidate, (cost, j, 1))
        if cost+c >= dist[j]: continue
        dist[j] = cost+c
        heappush(candidate, (cost+c, j, 0))
      else:
        if cost+c >= dist[j + n]: continue
        dist[j + n] = cost+c
        heappush(candidate, (cost+c, j, 1))
 
inf = 10**18+1
n, m = map(int, input().split(" "))

EDGES = [set() for _ in range(n)]

for _ in range(m):
  a, b, c = [int(x)-1 for x in input().split(" ")]
  c += 1
  EDGES[a].add((c, b))
  EDGES[b].add((c, a))
 
to_ = [inf]*n
to_[0] = 0
to2 = [inf]*(2 * n)
to2[0] = 0
to2[n] = 0
dijkstra(0, to_, EDGES)
dijkstra2(0, to2, EDGES)
 
for i in range(n):
  print(to_[i] + to2[i + n])