#include #include using namespace std; using namespace atcoder; using ll=int; using ld=long double; ld pie=3.14159265359; ll inf=1000000001; ll mod=1000000007; int main(){ ll n,m; cin >> n >> m; vector>>g(n); for (ll i = 0; i < m; i++) { ll a,b,c; cin >> a >> b >> c; a--,b--; g[a].push_back({b,c}); g[b].push_back({a,c}); } vectormemo(n,inf),memo2(n,inf); memo[0]=0; priority_queue,vector>,greater>>que; que.push({0,0}); vectorch(n,0); while (!que.empty()) { ll v=que.top().second; que.pop(); ch[v]=0; for (ll i = 0; i < g[v].size(); i++) { if (memo[g[v][i].first]>memo[v]+g[v][i].second) { memo[g[v][i].first]=memo[v]+g[v][i].second; if (ch[g[v][i].first]==0) { que.push({memo[g[v][i].first],g[v][i].first}); ch[g[v][i].first]=1; } } if (memo2[g[v][i].first]>memo[v]) { memo2[g[v][i].first]=memo[v]; if (ch[g[v][i].first]==0) { que.push({memo2[g[v][i].first],g[v][i].first}); ch[g[v][i].first]=1; } } if (memo2[g[v][i].first]>memo2[v]+g[v][i].second) { memo2[g[v][i].first]=memo2[v]+g[v][i].second; if (ch[g[v][i].first]==0) { que.push({memo2[g[v][i].first],g[v][i].first}); ch[g[v][i].first]=1; } } } } ll ans=inf; cout << 0 << endl; for (ll i = 1; i < n; i++) { cout << memo[i]+memo2[i] << endl; } }