#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using uint = unsigned; using ull = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; template struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; template vector dijkstra(int s,vector>> &G){ auto n = G.size(); vector d(n, INF); priority_queue,vector>,greater<>> Q; d[s] = 0; Q.emplace(0, s); while(!Q.empty()){ T cost; int i; tie(cost, i) = Q.top(); Q.pop(); if(d[i] < cost) continue; for (auto &&e : G[i]) { auto cost2 = cost + e.cost; if(d[e.to] <= cost2) continue; d[e.to] = cost2; Q.emplace(d[e.to], e.to); } } return d; } int main() { int n, m; cin >> n >> m; vector>> G(2*n); for (int i = 0; i < m; ++i) { int a, b, c, x; scanf("%d %d %d %d", &a, &b, &c, &x); a--; b--; if(x){ G[a].emplace_back(b+n, c); G[b].emplace_back(a+n, c); G[a+n].emplace_back(b+n, c); G[b+n].emplace_back(a+n, c); }else { G[a].emplace_back(b, c); G[b].emplace_back(a, c); G[a+n].emplace_back(b+n, c); G[b+n].emplace_back(a+n, c); } } auto d = dijkstra(n-1, G); for (int i = 0; i < n-1; ++i) { printf("%lld\n", d[i+n]); } return 0; }