#include #include #include using namespace std; const long long inf = 1LL << 61; struct edge { int to; long long cost; }; struct state { int pos; long long cost; }; bool operator<(const state& s1, const state& s2) { return s1.cost > s2.cost; } vector shortest_path(int src, vector > &G) { int N = G.size(); vector dist(N, inf); dist[src] = 0; priority_queue que; que.push(state{ src, 0 }); while (!que.empty()) { int u = que.top().pos; que.pop(); for (edge e : G[u]) { if (dist[e.to] > dist[u] + e.cost) { dist[e.to] = dist[u] + e.cost; que.push(state{ e.to, dist[e.to] }); } } } return dist; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector > G(2 * N); for (int i = 0; i < M; ++i) { int A, B, C; cin >> A >> B >> C; --A, --B; G[A].push_back(edge{ B, C }); G[A + N].push_back(edge{ B + N, C }); G[A].push_back(edge{ B + N, 0 }); G[B].push_back(edge{ A, C }); G[B + N].push_back(edge{ A + N, C }); G[B].push_back(edge{ A + N, 0 }); } vector d = shortest_path(0, G); for (int i = 0; i < N; ++i) { long long ans = inf; ans = min(ans, d[i] * 2); ans = min(ans, d[i] + d[i + N]); cout << ans << '\n'; } return 0; }