import heapq INF = 10**18 def dijkstra(s, edge): n = len(edge) dist = [INF]*n prev = [-1]*n dist[s] = 0 edgelist = [] heapq.heappush(edgelist,(dist[s], s)) while edgelist: minedge = heapq.heappop(edgelist) if dist[minedge[1]] < minedge[0]: continue v = minedge[1] for e in edge[v]: if dist[e[1]] > dist[v]+e[0]: dist[e[1]] = dist[v]+e[0] prev[e[1]] = v heapq.heappush(edgelist,(dist[e[1]], e[1])) return dist, prev import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) g = [[] for i in range(2*n)] for i in range(m): a, b, c, x = map(int, input().split()) a, b = a-1, b-1 a0, a1, b0, b1 = a, a+n, b, b+n if x == 0: g[a0].append((c, b0)) g[a1].append((c, b1)) g[b0].append((c, a0)) g[b1].append((c, a1)) else: g[a1].append((c, b0)) g[a1].append((c, b1)) g[b1].append((c, a0)) g[b1].append((c, a1)) dist, _ = dijkstra(2*n-1, g) for i in range(n-1): print(dist[i])