import sys from heapq import heapify,heappop,heappush input=sys.stdin.readline write=sys.stdout.write N,M=map(int,input().split()) E=[[] for _ in range(2*N+1)] for _ in range(M): a,b,c=map(int,input().split()) E[a].append((b,c)) E[a].append((b+N,c)) E[a+N].append((b+N,c)) E[b].append((a,c)) E[b].append((a+N,c)) E[b+N].append((a+N,c)) inf=float("inf") T=[inf]*(2*N+1) T[1]=0 Q=[(0,1)] while Q: d,x=heappop(Q) if T[x]d+c: T[y]=d+c heappush(Q,(d+c,y)) X=[T[x]+T[x+N] if x!=1 else 0 for x in range(1,N+1)] write("\n".join(map(str,X)))