#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector<vector<Edge>>; using pli=pair<ll,int>; template<class T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m; cin>>n>>m; Graph G(2*n); rep(i,m){ int a,b,c,x; cin>>a>>b>>c>>x; a--,b--; G[a].push_back(Edge(b,c)); G[b].push_back(Edge(a,c)); G[a+n].push_back(Edge(b+n,c)); G[b+n].push_back(Edge(a+n,c)); if(x==1){ G[a].push_back(Edge(b+n,c)); G[b].push_back(Edge(a+n,c)); G[a+n].push_back(Edge(b,c)); G[b+n].push_back(Edge(a,c)); } } vector<ll> dist(2*n,INF); int s=2*n-1; dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } rep(i,n-1) cout<<dist[i]<<endl; return 0; }