#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) {} }; constexpr int MX = 2e5+4; vector> G(MX); vector d1(MX, LINF); int n,m; void dijkstra(int s, vector &d) { priority_queue, greater > que; que.push({0, s}); d[s+n] = 0; 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}); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); 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); G[a].emplace_back(b+n, 0); G[b].emplace_back(a+n, 0); G[a+n].emplace_back(b+n, c); G[b+n].emplace_back(a+n, c); // cout << G[a].back().to << " " << G[b].back().to << endl; } dijkstra(1, d1); FOR(i,1,n) { // cout << d1[i] << " "; cout << d1[i] + d1[i+n] << endl; } return 0; }