#include #define rep(i,n) for(int i=0;i ; using tp = tuple; const int INF = 1e9; const int MOD = 1000000007; int n = 100005,m = 200005; vector> graph(n,vector

()); vector dijkstra(ll start){ vector shortest(n); vector visited(n,false); priority_queue,vector>,greater>> pq; pq.push(make_pair(0,start)); while (!pq.empty()){ pair now = pq.top(); pq.pop(); ll cost,node; tie(cost,node) = now; if(visited[node]){ continue; }else{ shortest[node] = cost; visited[node] = true; for(pair next:graph[node]){ ll next_cost,next_node; tie(next_cost,next_node) = next; pq.push(make_pair(cost+next_cost,next_node)); } } } return shortest; } vector dijkstra2(int start){ vector res(n,0); vector seen(n,false); priority_queue,greater> pq; pq.push(tp(0,0,0)); while(!pq.empty()){ ll d = get<0>(pq.top()) + get<1>(pq.top()); ll mx = get<1>(pq.top()); ll node = get<2>(pq.top()); pq.pop(); if(seen[node]) continue; else{ res[node] = d - mx; seen[node] = true; for(P next:graph[node]){ ll next_cost,next_node ; tie(next_cost,next_node) = next; ll d_ = d + next_cost; ll mx_ = max(mx,next_cost); pq.push(tp(d_-mx_,mx_,next_node)); } } } return res; } int main(){ cin >> n >> m; rep(i,m){ ll a,b,c; cin >> a >> b >> c; --a;--b; graph[a].push_back(P(c,b)); graph[b].push_back(P(c,a)); } vector dis1 = dijkstra(0); vector dis2 = dijkstra2(0); rep(i,n){ cout << dis1[i] + dis2[i] << '\n'; } return 0; }