#include using namespace std; using ll = long long; struct State { int at; ll cost; int used; int prev; State(int at, ll cost, int prev) : at(at), cost(cost), used(false), prev(prev) {} State(int at, ll cost, int used, int prev) : at(at), cost(cost), used(used), prev(prev) {} bool operator>(const State& s) const { return cost > s.cost; } }; struct Edge { int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; typedef vector > AdjList; //隣接リスト const ll INF = 1e18; const int NONE = -1; AdjList graph; //sは始点、mincは最短経路のコスト、Prevは最短経路をたどる際の前の頂点 void dijkstra(int s, vector< vector >& minc){ priority_queue, greater > pq; pq.push(State(s, 0, NONE)); while(!pq.empty()) { State cur = pq.top(); pq.pop(); if (minc[cur.used][cur.at] <= cur.cost) continue; minc[cur.used][cur.at] = cur.cost; for(Edge e : graph[cur.at]) { ll cost = cur.cost + e.cost; if (minc[cur.used][e.to] <= cost) continue; pq.push(State(e.to, cost, cur.used, cur.at)); if (!cur.used) { cost = cur.cost; if (minc[1][e.to] <= cost) continue; pq.push(State(e.to, cost, true, cur.at)); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; graph.resize(n); for (int i = 0; i < m; i++) { int a, b; ll c; cin >> a >> b >> c; a--; b--; graph[a].emplace_back(b, c); graph[b].emplace_back(a, c); } vector< vector > minc(2, vector(n, INF)); dijkstra(0, minc); for (int i = 0; i < n; i++) { cout << minc[0][i] + minc[1][i] << endl; } return 0; }