#include <stdio.h> #include <vector> #include <queue> #define MAX (long long int)1e16 struct str{ int first; int second; long long int third; }; bool operator<(str a, str b) { return a.third>b.third; } std::priority_queue<str> Q; std::vector<str> V[200010]; long long int dist[200010][3]; int main() { int a,b; scanf("%d%d",&a,&b); for(int i=1;i<=b;i++) { int c,d,e,f; scanf("%d%d%d%d",&c,&d,&e,&f); V[c].push_back({d,e,f}); V[d].push_back({c,e,f}); } for(int i=1;i<=a;i++) dist[i][0] = dist[i][1] = MAX; Q.push({a,0,0}); dist[0][0] = 0; while(!Q.empty()) { str A = Q.top(); Q.pop(); if(dist[A.first][A.second]<A.third) continue; for(int i=0;i<V[A.first].size();i++) { str B = V[A.first][i]; if(B.third==1) { if(dist[B.first][1]>A.third + B.second) { dist[B.first][1] = A.third + B.second; Q.push({B.first,1,A.third+B.second}); } } else { if(dist[B.first][A.second]>A.third + B.second) { dist[B.first][A.second] = A.third + B.second; Q.push({B.first,A.second,A.third+B.second}); } } } } for(int i=1;i<a;i++) printf("%lld\n",dist[i][1]); }