#include using namespace std; using ll = long long; using pll = pair; using vl = vector ; //1D using vvl = vector ;//2D using vvvl = vector ;//3D using vvvvl = vector;//4D using vvvvvl = vector;//5D using vvvvvvl = vector;//6D using vvvvvvvl = vector;//7D using vp = vector ; //1D using vvp = vector ;//2D using vvvp = vector ;//3D using vvvvp = vector;//4D using vvvvvp = vector;//5D using vvvvvvp = vector;//6D using vvvvvvvp = vector;//7D using vi = vector ; //1D using vvi = vector ;//2D using vvvi = vector ;//3D using vvvvi = vector;//4D using vvvvvi = vector;//5D using vvvvvvi = vector;//6D using vvvvvvvi = vector;//7D using vb = vector ; //1D using vvb = vector ;//2D using vvvb = vector ;//3D using vvvvb = vector;//4D using vvvvvb = vector;//5D using vvvvvvb = vector;//6D using vvvvvvvb = vector;//7D using vs = vector ; //1D using vvs = vector ;//2D using vvvs = vector ;//3D using vvvvs = vector;//4D using vvvvvs = vector;//5D using vvvvvvs = vector;//6D using vvvvvvvs = vector;//7D [[maybe_unused]] const ll INF = 2e18 ; [[maybe_unused]] const ll MOD = 998244353; #define rep(i,a,b) for(ll i=(ll)a; i<(ll)b; i++) #define rrep(i,a,b) for(ll i=(ll)b-1; i>=(ll)a; i--) #define all(vec1) (vec1).begin(), (vec1).end() #define yn(b,ex) if(1){if(b)cout << "Yes" << endl;else cout << "No" << endl ;if(ex)return 0;} #define debug(var) cerr << #var << " : " << var << endl; //fastio struct FastIO { FastIO() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } fastio; //あまり(負の数対応) template T ovr(T a,T b){ T ret=a%b; if(ret<0)ret+=b; return ret; } const string MOD_bi = "111111111111111111111110110111"; //MOD下での逆元 ll minv(ll ina){ ll a = ina % MOD; ll ret = 1; ll V = a; rep(i,0,MOD_bi.size()){ if(MOD_bi[i]=='1')ret=(ret*V)%MOD; V=(V*V)%MOD; } return ret; } //指数をある値で割った余り ll mpow(ll a , ll b , ll M){ ll ret = 1; ll V = a; rep(i,0,64){ if((b >> i) & 1)ret=(ret*V)%M; V=(V*V)%M; } return ret; } /////////main///////// int main() { ll N,M,C; cin >> N >> M >> C; vvp G(N); while (M--) { ll u, v, w; cin >> u >> v >> w; u -- , v -- ; G[u].push_back({w,v}); G[v].push_back({w,u}); } cerr << "===OUTPUT===" << endl; //頂点0からダイクストラする vl dp(N, INF); set st; rep(i,0,N) st.insert({INF, i}); auto upd_dist = [&st](vl&DP, ll i, ll x) -> ll { if (DP[i] <= x || st.find({DP[i], i}) == st.end()) { return 0; } st.erase({DP[i], i}); DP[i] = x; st.insert({DP[i], i}); return 0; }; upd_dist(dp,0,0); rep(i,0,N) { auto from = st.begin(); pll fromp = *from; st.erase(from); //fromから伸ばす for (pll x : G[fromp.second]) { upd_dist(dp,x.second, dp[fromp.second] + x.first + C); } } //頂点N-1からダイクストラ、ただしクーポンを途中で一枚消費できる //クーポンを使う、使わないで拡張ダイクストラ? st.clear(); rep(i,0,2*N) st.insert({INF, i}); vl dp2(N * 2, INF); upd_dist(dp2,2*N-1,0); rep(i,0,2*N) { auto from = st.begin(); pll fromp = *from; st.erase(from); //fromから伸ばす if (fromp.second < N) { for (pll x : G[fromp.second]) { upd_dist(dp2, x.second, dp2[fromp.second] + x.first + C); } } else { for (pll x : G[fromp.second - N]) { upd_dist(dp2, x.second + N, dp2[fromp.second] + x.first + C); } for (pll x : G[fromp.second - N]) { upd_dist(dp2, x.second, dp2[fromp.second] + C); } } } rep(i,1,N) { cout << min(dp[N - 1], dp[i] + min(dp2[i], dp2[i + N])) << endl; } }