#include #define mp make_pair #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair; const ll INF = 1LL << 30; const ll LINF = 1LL << 60; const double eps = 1e-9; const ll MOD = 1000000007LL; struct edge { int to; ll cost; }; int main() { int n, m; cin >> n >> m; vector> G(n); for(int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; --a; --b; G[a].push_back({b, c}); G[b].push_back({a, c}); } priority_queue, vector>, greater>> q; vector> d(n, vector(2, LINF)); d[0][0] = 0; d[0][1] = 0; q.push(mp(P(0, 0), 0)); q.push(mp(P(0, 0), 1)); while(!q.empty()) { auto p = q.top(); q.pop(); int v = p.first.second, f = p.second; for(auto e : G[v]) { if(d[e.to][f] > d[v][f] + e.cost) { d[e.to][f] = d[v][f] + e.cost; q.push(mp(P(d[e.to][f], e.to), f)); } if(f == 0) { if(d[e.to][1] > d[v][0]) { d[e.to][1] = d[v][0]; q.push(mp(P(d[e.to][1], e.to), 1)); } } } } for(int i = 0; i < n; i++) { cout << d[i][0] + d[i][1] << endl; } }