#include using namespace std; struct edge { int to; long long dist; edge(int t, long long d) { to = t; dist = d; } }; int main() { int n, m; cin >> n >> m; vector v[n]; for (int i = 0; i < m; i++) { int a, b; long long c; cin >> a >> b >> c; v[a-1].emplace_back(b-1, c); v[b-1].emplace_back(a-1, c); } vector d(n, 1e17), d2(n, 1e17); d[0] = 0; d2[0] = 0; priority_queue> pq; pq.push({d[0], 0}); while (!pq.empty()) { int cur = pq.top().second; long long dist = -pq.top().first; pq.pop(); if (dist != d[cur]) continue; for (auto e: v[cur]) { if (d[e.to] > d[cur] + e.dist) { d[e.to] = d[cur] + e.dist; pq.push({-d[e.to], e.to}); } } } pq.push({d2[0], 0}); while (!pq.empty()) { int cur = pq.top().second; long long dist = -pq.top().first; pq.pop(); if (dist != d2[cur]) continue; for (auto e: v[cur]) { if (d2[e.to] > min(d2[cur] + e.dist, d[cur])) { d2[e.to] = min(d2[cur] + e.dist, d[cur]); pq.push({-d2[e.to], e.to}); } } } for (int i = 0; i < n; i++) { cout << d[i] + d2[i] << endl; } return 0; }