#include #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = std::int64_t; using P = std::tuple; using T = std::tuple; constexpr ll INF = std::numeric_limits::max() / 2; int N, M; std::vector

G[100100]; std::priority_queue, std::greater> pq; ll dist[100100][2]; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N >> M; for(int i=0;i> a >> b >> c; G[a].emplace_back(b, c); G[b].emplace_back(a, c); } std::fill(&dist[0][0], &dist[0][0] + 100100 * 2, INF); dist[1][0] = 0; dist[1][1] = 0; pq.emplace(0, 1, 0); until(pq.empty()){ int v, t; ll d; std::tie(d, v, t) = pq.top(); pq.pop(); if(d > dist[v][t]){ continue; } for(auto &e : G[v]){ int w, c; std::tie(w, c) = e; if(d + c < dist[w][t]){ dist[w][t] = d + c; pq.emplace(dist[w][t], w, t); } } if(t == 0){ for(auto &e : G[v]){ int w; std::tie(w, std::ignore) = e; if(d < dist[w][1]){ dist[w][1] = d; pq.emplace(dist[w][1], w, 1); } } } } for(int i=1;i<=N;++i){ ll mn = dist[i][0] + dist[i][1]; std::cout << mn << std::endl; } }