#include #include #include #include #include #include #include #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } template bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template void input(Ts&... ts) { (cin >> ... >> ts); } template istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on using T = tuple; #include int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; vector> g(n); rep(i, 0, m) { int a, b, c, x; cin, a, b, c, x; a--; b--; g[a].emplace_back(c, b, x > 0); g[b].emplace_back(c, a, x > 0); } priority_queue, greater> pq; const ll inf = 1LL << 60; auto cost = make_v(n, 2, inf); cost[n - 1][0] = 0; pq.emplace(0, n - 1, 0); while (pq.size()) { auto [c, v, x] = pq.top(); pq.pop(); if (cost[v][x] < c) continue; cost[v][x] = c; for (auto [nc, nv, nx] : g[v]) { if (chmin(cost[nv][x || nx], c + nc)) { pq.emplace(c + nc, nv, x || nx); } } } rep(i, 0, n - 1) { print(cost[i][1]); } return 0; }