#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; typedef tupleT; int n, m; vector>E[101010]; void dijkstra(int n,int m,vector> &dp) { dp[0][0] = 0; dp[1][0] = 0; priority_queue,greater>Q; Q.push({0,0,0}); Q.push({0,1,0}); while (!Q.empty()) { auto t = Q.top(); Q.pop(); ll cost = get<0>(t); ll state = get<1>(t); ll v = get<2>(t); if (cost > dp[state][v])continue; rep(i, 0, E[v].size()) { auto &e = E[v][i]; if (dp[state][e.first] > cost + e.second) { dp[state][e.first] = cost + e.second; Q.push({dp[state][e.first],state,e.first}); } if (state == 0) { if (dp[1][e.first] > cost) { dp[1][e.first] = cost; Q.push({dp[1][e.first],1,e.first}); } } } } } int main() { cin >> n >> m; rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; a--, b--; E[a].pb({b,c}); E[b].pb({a,c}); } vector>dp(2,vector(n,inf)); dijkstra(n, m, dp); rep(i, 0, n) { cout << dp[0][i] + dp[1][i] << endl; } return 0; }