/* -*- coding: utf-8 -*- * * 3393.cc: No.3393 Move on Highway - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_N2 = MAX_N * 2; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using pii = pair; using pli = pair; using vpii = vector; /* global variables */ vpii nbrs[MAX_N]; ll ds0[MAX_N2], ds1[MAX_N2]; /* subroutines */ void dijkstra(int n, int st, int c, ll ds[]) { fill(ds, ds + n * 2, LINF); ds[st << 1] = 0; priority_queue q; q.push({0, st << 1}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; int ux = (u >> 1), uy = (u & 1); for (auto [vx, w]: nbrs[ux]) { int v = (vx << 1) | uy; ll vd = ud + w + c; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); if (uy == 0) { int v = (vx << 1) | 1; ll vd = ud + c; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } } } } /* main */ int main() { int n, m, c; scanf("%d%d%d", &n, &m, &c); for (int i = 0; i < m; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); u--, v--; nbrs[u].push_back({v, w}); nbrs[v].push_back({u, w}); } dijkstra(n, 0, c, ds0); dijkstra(n, n - 1, c, ds1); int gl = (n - 1) << 1; ll gd = ds0[gl]; for (int i = 1; i < n; i++) { ll mind = min(gd, ds0[i << 1] + ds1[(i << 1) | 1]); printf("%lld\n", mind); } return 0; }