from heapq import heapify, heappop, heappush import sys input = sys.stdin.buffer.readline def main(): N,M = map(int,input().split()) G = [[] for _ in range(N)] for i in range(M): a,b,c,x = map(int,input().split()) a -= 1; b -= 1 G[a].append((c,b,x)) G[b].append((c,a,x)) d = dijkstra_heap2(N-1,G) #研究所を始点に各家まで必ず動物を一回通る。 #print(d) for i in range(N-1): print(d[i][1]) def dijkstra_heap2(s,G): INF = float('inf') #S:start, V: node, E: Edge, G: Graph V = len(G) d = [[INF,INF] for _ in range(V)] #0:動物を取っていない、1:動物を取っている。 d[s][0] = 0 PQ = [] heappush(PQ,(0,s,0)) #距離、頂点、動物 while PQ: c,v,vani = heappop(PQ) if d[v][vani] < c: continue d[v][vani] = c for cost,u,uani in G[v]: if vani == 1: #既に動物を取っている if d[u][1] <= cost + d[v][1]: continue d[u][1] = cost + d[v][1] heappush(PQ,(d[u][1],u,1)) else: #vani = 0 if uani == 0: if d[u][0] <= cost + d[v][0]: continue d[u][0] = cost + d[v][0] heappush(PQ,(d[u][0],u,0)) else: #uani == 1 if d[u][1] <= cost + d[v][0]: continue d[u][1] = cost + d[v][0] heappush(PQ,(d[u][1],u,1)) return d if __name__ == '__main__': main()