#include #define rep(i,n) for(ll i=0, i##_len=(n); ibool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b P; ll dp[200010]; vector> road(200010); int main(){ ll N,M; cin >> N >> M; rep(i,M){ ll a,b,c; cin >> a >> b >> c; road[a].push_back(P(b,c)); road[a].push_back(P(b+N,0)); road[b].push_back(P(a,c)); road[b].push_back(P(a+N,0)); road[a+N].push_back(P(b+N,c)); road[b+N].push_back(P(a+N,c)); } priority_queue,greater

> q; q.push(P(1,0)); for(int i=2;i<=2*N;i++){ if(i!=N+1) dp[i] = (ll)1e18; } while(!q.empty()){ P p = q.top();q.pop(); ll num = p.first; ll cost = p.second; if(dp[num] < cost)continue; for(auto next_p: road[num]){ ll next_num = next_p.first; ll next_cost = next_p.second; if(dp[next_num] > cost+next_cost){ dp[next_num] = cost+next_cost; q.push(P(next_num,dp[next_num])); } } } REP(i,1,N+1){ cout << (dp[i]+dp[i+N]) << endl; } return 0; }