#include using namespace std; #include //using namespace atcoder; using ll = long long; using ull = unsigned long long; using i128 = __int128_t; using u128 = unsigned __int128_t; using mint = atcoder::static_modint<998244353>; const int mod = 998244353; #include mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}; int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; template bool chmin(T& a, const T& b){ if (b < a){ a = b; return true; } else { return false; } } template bool chmax(T& a, const T& b){ if (a < b){ a = b; return true; } else { return false; } } void solve(){ int n, m; cin >> n >> m; vector>> vec(n); for (int i = 0; i < m; i++){ int u, v, w; cin >> u >> v >> w; u--; v--; vec[u].push_back({v, w}); vec[v].push_back({u, w}); } vector> dist(n, vector (2, 2e18)); dist[0][0] = 0; dist[0][1] = 0; priority_queue, vector>, greater>> pq; pq.push({0, 0}); pq.push({0, 1}); while(!pq.empty()){ auto[a, b] = pq.top(); pq.pop(); for (auto d : vec[a]){ if (b == 0){ if (dist[d.first][0] > dist[a][b] + d.second){ dist[d.first][0] = dist[a][b] + d.second; pq.push({d.first, 0}); } if (dist[d.first][1] > dist[a][b]){ dist[d.first][1] = dist[a][b]; pq.push({d.first, 1}); } } else { if (dist[d.first][1] > dist[a][b] + d.second){ dist[d.first][1] = dist[a][b] + d.second; pq.push({d.first, 1}); } } } } for (int i = 0; i < n; i++){ cout << dist[i][0] + dist[i][1] << '\n'; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while(t--){ cout << fixed << setprecision(15); solve(); } }