#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { int N, M; cin >> N >> M; vector> G(N); for (int i = 0; i < M; i++) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } vector> dist(N, vector(2, INF_ll)); min_priority_queue> pq; dist[0][0] = 0; pq.push({{0, 0}, 0}); while (!pq.empty()) { auto p = pq.top(); pq.pop(); ll d = p.first.first; ll c = p.first.second; ll u = p.second; if (dist[u][c] < d) { continue; } for (auto e : G[u]) { ll next = e.first; if (chmin(dist[next][c], e.second + d)) { pq.push({{dist[next][c], c}, next}); } if (c == 0) { if (chmin(dist[next][1], d)) { pq.push({{dist[next][1], 1}, next}); } } } } for (int i = 0; i < N; i++) { cout << dist[i][0] + min(dist[i][0], dist[i][1]) << endl; } return 0; }