#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; }; typedef pair P; int main() { int N, M; cin >> N >> M; vector> G(N * 2, vector()); vector d(N * 2, INF); 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 }); G[a].push_back({ b + N,0 }); G[b].push_back({ a + N,0 }); G[a + N].push_back({ b + N,c }); G[b + N].push_back({ a + N,c }); } priority_queue, greater

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