from sys import stdin import sys import heapq def Dijkstra(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 end_flag = [False] * len(lis) end_num = 0 q = [(0,start)] while len(q) > 0: ncost,now = heapq.heappop(q) if end_flag[now]: continue end_flag[now] = True end_num += 1 if end_num == len(lis): break for nex,ecost in lis[now]: if ret[nex] > ncost + ecost: ret[nex] = ncost + ecost heapq.heappush(q , (ret[nex] , nex)) return ret N,M = map(int,stdin.readline().split()) lis = [ [] for i in range(2*N) ] for i in range(M): A,B,C,X = map(int,stdin.readline().split()) A -= 1 B -= 1 lis[A].append( (B+X*N,C) ) lis[B].append( (A+X*N,C) ) lis[A+N].append( (B+N,C) ) lis[B+N].append( (A+N,C) ) dlis = Dijkstra(lis,N-1) for i in range(N-1): print (dlis[i+N])