#include"bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair; using pll = pair; #define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout<< #str << " " str< P; ll N, M; vector> G; vector d, d2; void dijkstra(int s) { priority_queue, greater

> que; d = vector(N, INFL); d[s] = 0; que.push({ 0,s }); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first)continue; for (auto e : G[v])if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push({ d[e.to],e.to }); } } } void dijkstra2(int s) { priority_queue, greater

> que; d2 = vector(N, INFL); d2[s] = 0; que.push({ 0,s }); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first)continue; for (auto e : G[v]) { ll use0 = d[v]; ll not0 = d2[v] + e.cost; ll score = min(use0, not0); if (d2[e.to] > score) { d2[e.to] = score; que.push({ d2[e.to],e.to }); } } } } int main() { cin >> N >> M; G.resize(N); REP(i, M) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({ b,c }); G[b].push_back({ a,c }); } dijkstra(0); dijkstra2(0); REP(i, N)cout << d[i] + d2[i] << endl; return 0; }