N,M = map(int,input().split()) G = [[] for _ in range(N+1)] for _ in range(M): a,b,c,x = map(int,input().split()) G[a].append((b,c,x>0)) G[b].append((a,c,x>0)) import heapq q = [] heapq.heapify(q) C = 10 ** 18 dist = [[C] * 2 for _ in range(N+1)] dist[N][0] = 0 heapq.heappush(q,(0,N,False)) while q: d,now,flag = heapq.heappop(q) if flag: if d > dist[now][1]:continue for v,c,x in G[now]: if dist[v][1] > d + c: dist[v][1] = d + c heapq.heappush(q,(d+c,v,True)) else: if d > dist[now][0] or d > dist[now][1]:continue for v,c,x in G[now]: if x: if dist[v][1] > d + c: dist[v][1] = d+c heapq.heappush(q,(d+c,v,True)) else: if dist[v][0] > d + c: dist[v][0] = d + c heapq.heappush(q,(d+c,v,False)) for i in range(1,N): print(dist[i][1])