#include using namespace std; int main() { int64_t n, m; cin >> n >> m; vector>> g(n); for (int i = 0; i < m; i++) { int64_t a, b, c; cin >> a >> b >> c; a--; b--; g[a].push_back({c, b}); g[b].push_back({c, a}); } vector> dist(n, vector(2, (1LL << 60))); dist[0][0] = 0; priority_queue>, vector>>, greater<>> pq; pq.push({dist[0][0], {0, 0}}); while (!pq.empty()) { int64_t score = pq.top().first; int x = pq.top().second.first; int y = pq.top().second.second; pq.pop(); if (dist[x][y] < score) { continue; } for (auto &p : g[x]) { int64_t cost = p.first; int to = p.second; if (dist[x][y] + cost < dist[to][y]) { dist[to][y] = dist[x][y] + cost; pq.push({dist[to][y], {to, y}}); } if (y == 0) { if (dist[x][y] < dist[to][1]) { dist[to][1] = dist[x][y]; pq.push({dist[to][1], {to, 1}}); } } } } cout << 0 << endl; for (int i = 1; i < n; i++) { cout << dist[i][0] + dist[i][1] << endl; } return 0; }