#include #include #include using namespace std; using ll = long long; struct edge { int to; ll cost; }; struct status { ll cost; int v; bool operator<(const status &rhs) const { return cost < rhs.cost; }; bool operator>(const status &rhs) const { return cost > rhs.cost; }; }; const ll INF = (1LL << 60) - 1; vector dijkstra(int s, int n, vector> &graph) { priority_queue, greater<>> que; vector dis(n, INF); dis[s] = 0; que.push({0, s}); while (!que.empty()) { status now = que.top(); que.pop(); if (dis[now.v] < now.cost)continue; for (auto next:graph[now.v]) { if (dis[next.to] > dis[now.v] + next.cost) { dis[next.to] = dis[now.v] + next.cost; que.push({dis[next.to], next.to}); } } } return dis; } int main() { int n, m; cin >> n >> m; vector> graph(n * 2); for (int i = 0; i < m; i++) { int u, v, cost; cin >> u >> v >> cost, u--, v--; graph[u].push_back({v, cost}), graph[v].push_back({u, cost}); graph[u].push_back({v + n, 0}), graph[v].push_back({u + n, 0}); graph[u + n].push_back({v + n, cost}), graph[v + n].push_back({u + n, cost}); } vector dis = dijkstra(0, n * 2, graph); cout << 0 << endl; for (int i = 1; i < n; i++) cout << dis[i] + dis[i + n] << "\n"; cout << flush; return 0; }