#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair; using vi = vector; using vl = vector; ld EPS = 1e-12; int INF = numeric_limits::max() / 2; int MOD = 1e9 + 7; #define rep(i,n) for(int i = 0; i < n; i++) #define all(obj) (obj).begin(), (obj).end() #define debug(x) cerr << #x << ": " << x << '\n' vector > edge(100010, vector(0)); //頂点iのj番目の辺の行き先 vector > dist(100010, vector(0)); //頂点iのj番目の辺の重み vector longest(100010,0); vector d(100010,-1); vector dn(100010,-1); ll dijkstra_prime(int from, int to, int v){ for(int i = 0; i < v; i++){ dn[i] = INF; } dn[from] = 0; priority_queue q; q.push(from); while(!q.empty()){ int now = q.top(); q.pop(); //その頂点からたどり着ける頂点の情報を更新する for(int j = 0; j < edge[now].size(); j++){ int next = edge[now][j]; ll nextd = dn[now] + longest[now] + dist[now][j]; ll nextlong = max(longest[now], dist[now][j]); if(nextd - nextlong < dn[next]){ dn[next] = nextd - nextlong; longest[next] = nextlong; q.push(next); } } } return dn[to]; } ll dijkstra(int from, int to, int v){ for(int i = 0; i < v; i++){ d[i] = INF; } d[from] = 0; priority_queue q; q.push(from); while(!q.empty()){ int now = q.top(); q.pop(); //その頂点からたどり着ける頂点の情報を更新する for(int j = 0; j < edge[now].size(); j++){ int next = edge[now][j]; ll nextd = d[now] + dist[now][j]; if(nextd < d[next]){ d[next] = nextd; q.push(next); } } } return d[to]; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m; cin >> n >> m; rep(i,m){ int a,b,c; cin >> a >> b >> c; a--;b--; edge[a].push_back(b); dist[a].push_back(c); edge[b].push_back(a); dist[b].push_back(c); } dijkstra(0,0,n); dijkstra_prime(0,0,n); rep(i,n){ cout << d[i] + dn[i] << '\n'; } return 0; }