#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(200010);//edge[i][j] firstがiからj番目のノード、secondがその重み ll dp[200010]; ll inf = 1e18; void dijkstra(int start){ priority_queue q; q.push(start); while(!q.empty()){ int now = q.top(); q.pop(); for(auto p: edge[now]){ int next = p.first; ll nextd = dp[now] + p.second; if(nextd < dp[next]){ dp[next] = nextd; q.push(next); } } } } 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; edge[a].push_back(make_pair(b,c)); edge[a].push_back(make_pair(b+n,0)); edge[b].push_back(make_pair(a,c)); edge[b].push_back(make_pair(a+n,0)); edge[a+n].push_back(make_pair(b+n,c)); edge[b+n].push_back(make_pair(a+n,c)); } for(int i = 1; i <= 2*n; i++){ if(i%n == 1) dp[i] = 0; else dp[i] = inf; } dijkstra(1); rep(i,n){ cout << dp[i+1] + dp[i+n+1] << '\n'; } return 0; }