#include #define INF 2147483647 #define INF_LL 9223372036854775807 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef unsigned long long int ull; struct edge { ll to; ll cost; }; // d v f typedef pair> P; int main() { int N, M; cin >> N >> M; vector> G(N, vector()); for (int i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({ b,c }); G[b].push_back({ a,c }); } vector d1(N, INF), d2(N, INF), d3(N, INF); priority_queue, greater

> q, q_; d1[0] = 0; d2[0] = 0, d3[0] = 0; q.push(P{ 0,{0,false} }); while (!q.empty()) { P p = q.top(); q.pop(); ll v = p.second.first; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if (d1[e.to] > p.first + e.cost) { d1[e.to] = p.first + e.cost; q.push(P{ d1[e.to],{ e.to, p.second.second } }); } if (d3[e.to] > p.first) { d3[e.to] = p.first; q_.push(P{ d3[e.to],{ e.to, true } }); } } } while (!q_.empty()) { P p = q_.top(); q_.pop(); ll v = p.second.first; if (d3[v] < p.first)continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if (d3[e.to] > p.first + e.cost) { d3[e.to] = p.first + e.cost; q_.push(P{ d3[e.to],{ e.to, p.second.second } }); } } } for (int i = 0; i < N; i++) { cout << min(d3[i] + d1[i],d1[i]*2) << endl; } }