import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n,m = list(map(int, input().split())) ns = [[] for _ in range(n)] s = 0 for i in range(m): a,b,c,x = map(int, input().split()) a -= 1 b -= 1 ns[a].append((c,b,x)) ns[b].append((c,a,x)) s += c from heapq import heappop as hpp, heappush as hp inf = 2*s + 10 vals = [[inf]*n for _ in range(2)] vals[0][n-1] = 0 q = [(0, n-1, 0)] while q: d,u,x = hpp(q) if vals[x][u]nd: vals[nx][v] = nd hp(q, (nd, v, nx)) ans = vals[1] write("\n".join(map(str, ans[:n-1])))