#include "bits/stdc++.h" #define ALL(x) x.begin(), x.end() #define LEN(x) (int)x.size() #define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0) using namespace std; typedef int64_t i64; typedef pair pii; templateinline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;} templateinline bool chmin(A &a, const B &b){return bc < that.c; } bool operator> (const P &that) const { return this->c > that.c; } }; int N, M; vector G[100010]; // dist[node][ticket-used] i64 dist[100010][2]; void dijkstra(int s) { priority_queue, greater

> pq; memset(dist, 0x3f, sizeof(dist)); pq.emplace(0, s, false); dist[s][false] = 0; dist[s][true] = 0; while( !pq.empty() ) { const auto now = move(pq.top()); pq.pop(); if (dist[now.to][now.used] < now.c) continue; for (const auto &e : G[now.to]) { const int nxt = e.second; const i64 ncost = e.first + now.c; if (chmin(dist[nxt][now.used], ncost)) pq.emplace(ncost, nxt, now.used); if (!now.used && chmin(dist[nxt][true], now.c)) pq.emplace(now.c, nxt, true); } } } signed main() { iostreamBooster(); cin >> N >> M; for (int i = 0; i < M; ++i) { int s, t, c; cin >> s >>t >> c; --s, --t; G[s].emplace_back(c, t); G[t].emplace_back(c, s); } dijkstra(0); for (int i = 0; i < N; ++i) { cout << dist[i][false] + dist[i][true] << '\n'; } return 0; }