#include using namespace std; using P = pair; using Graph = vector>; void dijkstra(const vector> &G, int s, vector &dist) { priority_queue, greater

> que; dist[s] = 0; que.emplace(dist[s], s); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (dist[v] < p.first) continue; for (auto &[dis, nv] : G[v]) { if (dist[nv] > dist[v] + dis) { dist[nv] = dist[v] + dis; que.emplace(dist[nv], nv); } } } } int main() { int N, M; cin >> N >> M; Graph G(N); vector> abcx; for (int i = 0; i < M; i++) { int a, b, c, x; cin >> a >> b >> c >> x; a--; b--; G[a].emplace_back(c, b); G[b].emplace_back(c, a); abcx.emplace_back(a, b, c, x); } vector dist(N, 1LL << 60); dijkstra(G, N-1, dist); vector

v; for (auto &[a, b, c, x] : abcx) { if (x) { v.emplace_back(dist[a] + c, b); v.emplace_back(dist[b] + c, a); } } G.emplace_back(v); dist.assign(N+1, 1LL << 60); dijkstra(G, N, dist); for (int i = 0; i < N-1; i++) cout << dist[i] << endl; }