#include using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; std::vector>> g; std::vector> solve(int s = 0) { using P = std::pair>; std::vector> min_cost(g.size(), std::vector(2, 1LL << 60)); std::priority_queue, std::greater

> qu; min_cost[s][0] = min_cost[s][1] = 0; qu.push({0, {0, 0}}); while(!qu.empty()) { auto p = qu.top(); qu.pop(); for(auto e: g[p.second.first]) { if(p.first + e.second < min_cost[e.first][p.second.second]) { min_cost[e.first][p.second.second] = p.first + e.second; qu.push({p.first + e.second, {e.first, p.second.second}}); } if(!p.second.second) { if(p.first >= min_cost[e.first][1]) continue; min_cost[e.first][1] = p.first; qu.push({p.first, {e.first, 1}}); } } } return min_cost; } int main() { int n, m; scanf("%d%d", &n, &m); g.resize(n); for(int i = 0; i < m; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); g[a - 1].push_back({b - 1, c}); g[b - 1].push_back({a - 1, c}); } auto min_cost = solve(); for(int i = 0; i < n; i++) { printf("%lld\n", min_cost[i][0] + min_cost[i][1]); } return 0; }