/** * author: zjs * created: 01.09.2026 20:29:22 **/ #include #include // does not include cassert since GCC 16. using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif struct Path { int to; long long cost; int coupon; }; bool operator<(Path a, Path b) { return a.cost > b.cost; } struct Edge { int to, w; }; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, c; cin >> n >> m >> c; vector> g(n + 1); for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; g[u].push_back({v, w}); g[v].push_back({u, w}); } priority_queue q; q.push({1, 0}); vector dist(n + 1, -1); while (!q.empty()) { Path p = q.top(); q.pop(); if (dist[p.to] != -1) continue; dist[p.to] = p.cost; for (Edge e : g[p.to]) { q.push({e.to, p.cost + e.w + c}); } } vector ans(n + 1, dist[n]); q.push({n, 0, 1}); vector> vis(n + 1, vector(2)); while (!q.empty()) { Path p = q.top(); q.pop(); if (vis[p.to][p.coupon]) continue; vis[p.to][p.coupon] = true; ans[p.to] = min(ans[p.to], dist[p.to] + p.cost); for (Edge e : g[p.to]) { q.push({e.to, p.cost + e.w + c, p.coupon}); if (p.coupon) q.push({e.to, p.cost + c, 0}); } } for (int i = 2; i <= n; i++) cout << ans[i] << '\n'; }