#pragma GCC target("avx2") #pragma GCC optimize("03") #pragma GCC optimize("unroll-loops") #include using namespace std; typedef long double ld; typedef long long ll; typedef unsigned long long ull; #define endl "\n" #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define rep(i,n) for(int i=0;i<(n);i++) #define PII pair #define PLL pair #define ALL(x) (x).begin(), (x).end() constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1; templateinline bool chmax(T &a, const T &b) { if (ainline bool chmin(T &a, const T &b) { if (binline int popcount(T a) {return __builtin_popcount(a);} //------------------- struct Edge { int to; ll cost; Edge(int to, ll ct): to(to), cost(ct) {} }; using TIIL = tuple; constexpr int MX = 1e5+4; vector> G(MX); vector d1(MX, LINF); vector d2(MX, LINF); void dijkstra(int s, vector &d) { priority_queue, greater > que; que.push({0, s}); while (!que.empty()) { PII p = que.top(); que.pop(); int v = p.second; if (d[v] <= p.first) continue; d[v] = p.first; for (auto e: G[v]) { if (d[e.to] > d[v] + e.cost) { // make code faster que.push({d[v] + e.cost, e.to}); } } } } void dijkstra2(int s, vector &d) { priority_queue, greater > que; que.push({0, s, 0}); while (!que.empty()) { auto [ct, to, mx] = que.top(); que.pop(); if (d[to] <= ct) continue; // cout << to << " " << ct << mx << endl; d[to] = ct; for (auto e: G[to]) { ll curmx = max(mx, e.cost); // cout << e.to << " " << d[e.to] << " " << d[to] + mx + e.cost - curmx << endl; if (d[e.to] > d[to] + mx + e.cost - curmx) { // make code faster que.push({d[to] + mx + e.cost - curmx, e.to, curmx}); // cout << e.to << endl; } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int n,m; cin >> n >> m; rep(i, m) { int a,b; ll c; cin >> a >> b >> c; G[a].emplace_back(b,c); G[b].emplace_back(a,c); // cout << G[a].back().to << " " << G[b].back().to << endl; } dijkstra(1, d1); dijkstra2(1, d2); FOR(i,1,n) { // cout << d1[i] << " "; cout << d1[i] + d2[i] << endl; } return 0; }