#include using namespace std; using lint = long long; lint n, m; typedef tuple P; struct edge{lint to, cost;}; vector > G; vector > dist; const lint INF= 1e18; void dij(int start){ priority_queue, greater

> que; dist[0][0] = 0; dist[1][0] = 0; que.push(P(0, 0, 0)); while(que.size()){ P p = que.top(); que.pop(); int d = get<0>(p), u = get<1>(p), flag = get<2>(p); if(dist[flag][u] < d) continue; for(auto e : G[u]){ if(dist[flag][e.to] > dist[flag][u] + e.cost){ dist[flag][e.to] = dist[flag][u] + e.cost; que.push(P(dist[flag][e.to], e.to, flag)); } if(flag == 0 && dist[1][e.to] > dist[0][u]){ dist[1][e.to] = dist[0][u]; que.push(P(dist[1][e.to], e.to, 1)); } } } } signed main(){ cin >> n >> m; G.resize(n); dist.resize(2, vector (n, INF)); for(int i = 0; i < m; i++){ lint a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back(edge{b, c}); G[b].push_back(edge{a, c}); } dij(0); for(int i = 0; i < n; i++) cout << dist[0][i] + dist[1][i] << '\n'; }