n,m=map(int,input().split()) e=[[] for i in range(n*2)] for i in range(m): a,b,c=map(int,input().split()) a-=1 b-=1 e[a]+=[(b,c)] e[a]+=[(b+n,0)] e[a+n]+=[(b+n,c)] e[b]+=[(a,c)] e[b]+=[(a+n,0)] e[b+n]+=[(a+n,c)] X=10**20 from heapq import heappush,heappop v=[X]*n*2 s=0 v[s]=0 q=[(v[s],s)] while len(q)>0: sc,sp=heappop(q) if sc>v[sp]: continue for tp,tc in e[sp]: if v[tp]>sc+tc: v[tp]=sc+tc heappush(q,(v[tp],tp)) v1=v.copy() v=[X]*n*2 s=0+n v[s]=0 q=[(v[s],s)] while len(q)>0: sc,sp=heappop(q) if sc>v[sp]: continue for tp,tc in e[sp]: if v[tp]>sc+tc: v[tp]=sc+tc heappush(q,(v[tp],tp)) v2=v.copy() for i in range(n): print(min(v1[i]+v2[i+n],v1[i+n]+v2[i+n]))