#include #define rep(i,n,m) for(int i = (n); i <(m); i++) #define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--) using namespace std; using ll = long long; using pll = pair; using tlll = tuple; const int MAX_N = 100000; const ll INF = 1e18; struct edge{int to, weight;}; vector from[MAX_N]; int main() { int n, m; cin >> n >> m; rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; --a, --b; edge e{b, c}; from[a].push_back(edge{b, c}); from[b].push_back(edge{a, c}); } vector dis(2*n, INF); priority_queue, greater> que; que.push(make_pair(0, 0)); while (que.size() > 0) { ll node, distance; tie(node, distance) = que.top(); que.pop(); if (dis[node] < distance) continue; dis[node] = distance; if (n <= node) for (edge e: from[node % n]) que.push(make_pair(n + e.to, (ll)distance + e.weight)); else { for (edge e: from[node]) { que.push(make_pair(e.to, (ll) distance + e.weight)); que.push(make_pair(e.to + n, (ll) distance)); } } } rep(i, 0, n) cout << (ll) dis[i] + dis[n + i] << endl; // cout << dis[i] << endl; return 0; }