#include using namespace std; const long long INF = 1LL<<60; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector > > edges(n); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; --a, --b; edges[a].emplace_back(b, c); edges[b].emplace_back(a, c); } vector > dist(n, vector(2, INF)); priority_queue, vector>, greater> > Q; for (int x = 0; x < 2; x++) { dist[0][x] = 0; Q.emplace(dist[0][x], 0, x); } while (!Q.empty()) { long long cost; int v; int x; tie(cost, v, x) = Q.top(); Q.pop(); if (dist[v][x] < cost) continue; for (auto &[w, weight]: edges[v]) { if (dist[v][x] + weight < dist[w][x]) { dist[w][x] = dist[v][x] + weight; Q.emplace(dist[w][x], w, x); } if (!x && dist[v][x] < dist[w][x+1]) { dist[w][x+1] = dist[v][x]; Q.emplace(dist[w][x+1], w, x+1); } } } for (int i = 0; i < n; i++) cout << dist[i][0] + dist[i][1] << endl; return 0; }