#include #include #include using namespace std; using ll = long long int; constexpr ll INF = 1LL << 60; struct Node{ int to; ll cost; int isused; bool operator>(const Node &other) const { if(this->cost != other.cost) return this->cost > other.cost; else return this->isused > other.isused; } }; int main(){ int n, m; cin >> n >> m; vector> G(n); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c, 0}); G[b].push_back({a, c, 0}); } vector> dist(n, vector(2, INF)); dist[0][0] = 0; dist[0][1] = 0; priority_queue, greater> Q; Q.push({0, 0, 0}); while(Q.size()){ auto ccur = Q.top(); Q.pop(); int cur = ccur.to; ll ccost = ccur.cost; int isused = ccur.isused; if(ccost > dist[cur][isused]) continue; for(auto &p: G[cur]){ if(isused == 0 && dist[p.to][1] > dist[cur][isused]){ dist[p.to][1] = dist[cur][isused]; Q.push({p.to, dist[p.to][1], 1}); } if(dist[p.to][isused] > dist[cur][isused] + p.cost){ dist[p.to][isused] = dist[cur][isused] + p.cost; Q.push({p.to, dist[p.to][isused], isused}); } } } for(int i = 0; i < n; i++){ cout << dist[i][0] + dist[i][1] << endl; } return 0; }