#include using namespace std; #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif #define int long long const int INF = 1LL << 60; struct edge{ int to,cost; }; typedef tuple P; signed main(){ int n, m; cin >> n >> m; vector> G(n); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--, b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } priority_queue,greater

> que; vector> dp(2, vector(n, INF)); dp[0][0] = dp[1][0] = 0; que.push({0, 0, 0}); //{最短距離,頂点} while( !que.empty() ){ P p = que.top(); que.pop(); int d = get<0>(p), u = get<1>(p), flag = get<2>(p); if(dp[flag][u] < d) continue; for(auto e : G[u]){ if(dp[flag][e.to] > dp[flag][u] + e.cost){ dp[flag][e.to] = dp[flag][u] + e.cost; que.push( {dp[flag][e.to], e.to, flag} ); } if(flag == 0 && dp[1][e.to] > dp[0][u]){ dp[1][e.to] = dp[0][u]; que.push( {dp[1][e.to], e.to, 1} ); } } } for(int i = 0; i < n; i++){ cout << dp[0][i] + dp[1][i] << endl; } return 0; }