#include "bits/stdc++.h" using namespace std; using P = pair; struct edge {int to; long c;}; void solve() { int n, m; cin >> n >> m; vector dist(n, 1e18); dist[0] = 0; vector g[n]; while(m--) { int a, b; long c; cin >> a >> b >> c; a--, b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } priority_queue, greater

> q; q.push({0, 0}); while(!q.empty()) { auto p = q.top(); q.pop(); int v = p.second; long c = p.first; if (dist[v] < c) continue; for (auto np : g[v]) { int nv = np.to; long nc = np.c + dist[v]; if (dist[nv] > nc) { dist[nv] = nc; q.push({nc, nv}); } } } for (int i = 0; i < n; i++) { long ans = dist[i], plus = dist[i]; for (auto e : g[i]) { plus = min(plus, dist[e.to]); } ans += plus; cout << ans << endl; } } int main(void) { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }