import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # md = 10**9+7 md = 998244353 from heapq import * n,m=LI() s=n to=[[] for _ in range(n)] for _ in range(m): u,v,c,x=LI() u,v=u-1,v-1 if x: to+=[[],[]] to[u].append((s,c)) to[s].append((v,0)) to[v].append((s+1,c)) to[s+1].append((u,0)) s+=2 else: to[u].append((v,c)) to[v].append((u,c)) d1=[inf]*s d1[n-1]=0 hp=[(0,n-1)] while hp: d,u=heappop(hp) if d>d1[u]:continue for v,c in to[u]: nd=d+c if nd>=d1[v]:continue d1[v]=nd heappush(hp,(nd,v)) d2=[inf]*s hp=[] for u in range(n,s): d2[u]=d1[u] heappush(hp,(d2[u],u)) while hp: d,u=heappop(hp) if d>d2[u]:continue for v,c in to[u]: nd=d+c if nd>=d2[v]:continue d2[v]=nd heappush(hp,(nd,v)) print(*d2[:n-1],sep="\n")