n,m=map(int,input().split()) abcx=[list(map(int,input().split())) for _ in range(m)] g=[[] for _ in range(n)] for a,b,c,x in abcx: a,b=a-1,b-1 g[a].append([b,c,x]) g[b].append([a,c,x]) inf=float('inf') seen=[inf]*(2*n) todo=[[0,2*n-1]] seen[-1]=0 from heapq import heappop,heappush while todo: d,v=heappop(todo) if v>=n: for nv,nd,x in g[v-n]: if x==1: if seen[nv]>d+nd: seen[nv]=d+nd heappush(todo,[d+nd,nv]) else: if seen[nv+n]>d+nd: seen[nv+n]=d+nd heappush(todo,[d+nd,nv+n]) else: for nv,nd,x in g[v]: if seen[nv]>d+nd: seen[nv]=d+nd heappush(todo,[d+nd,nv]) for i in range(n-1): print(seen[i])