#include #include #include #include #include using namespace std; const long long INF = 1LL << 60; // 1.15x10^18 template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using edge = pair; using Graph = vector>; vector dijkstra(const Graph &g, int s) { vector dist(g.size(), INF); using Pi = pair; priority_queue, greater> que; dist[s] = 0; que.emplace(dist[s], s); while (!que.empty()) { long long cost; int u; tie(cost, u) = que.top(); que.pop(); if (dist[u] < cost) continue; for (auto &e: g[u]) { int v; long long nc; tie(v, nc) = e; if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v); } } return dist; } int main() { int n, m; cin >> n >> m; Graph g(n * 2); while (m--) { int a, b, c; cin >> a >> b >> c; a--, b--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); g[a].emplace_back(b + n, 0); g[b].emplace_back(a + n, 0); g[a + n].emplace_back(b + n, c); g[b + n].emplace_back(a + n, c); } g[0].emplace_back(n, 0); auto dp = dijkstra(g, 0); for (int i = 0; i < n; i++) cout << dp[i] + dp[i + n] << endl; return 0; }