#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; using Edge = pair; const ll INF = 1LL<<50; using Graph = vector>; template vector> dijkstra2(const Graph &G, int s){ vector> dist(2,vector((int)G.size(),INF)); priority_queue, vector>, greater> > que; dist[0][s] = 0; que.push(make_pair(Edge(0,s),0));//暫定距離+頂点+チケット while (!que.empty()){ pair e = que.top(); que.pop(); int v = e.first.second; int use = e.second; if (dist[use][v] < e.first.first) continue; for (auto p : G[v]) { if (dist[use][p.first] > dist[use][v] + p.second) { dist[use][p.first] = dist[use][v] + p.second; que.push(make_pair(Edge(dist[use][p.first],p.first),use)); } if (!use) { if (dist[1][p.first] < e.first.first) continue; dist[1][p.first] = e.first.first; que.push(make_pair(Edge(dist[1][p.first],p.first),1)); } } } return dist; } int main(){ int n, m; cin >> n >> m; Graph G(n); rep(i,m) { int a, b, c; cin >> a >> b >> c; a--;b--; G[a].push_back({b,c}); G[b].push_back({a,c}); } auto dist2 = dijkstra2(G,0); rep(i,n) { cout << dist2[0][i] + min(dist2[0][i], dist2[1][i]) << endl; } return 0; }