#include using namespace std; typedef long long ll; int N,M,used[1010] = {}; ll cost[1010][1010] = {},ans[1010] = {},inf = 1e18; ll dist[1010][1010] = {};//辺iのコストを0にしたときの1からの距離の最小値 void dijkstra(int id,int a,int b){ for(int i=1;i<=N;i++){ dist[id][i] = inf; used[i] = 0; } dist[id][1] = 0; while(1){ int u = -1; for(int i=1;i<=N;i++){ if(used[i]==0 && (u==-1 || dist[id][u]>dist[id][i])){ u = i; } } used[u] = 1; if(u==-1) break; for(int i=1;i<=N;i++){ ll c = cost[u][i]; if(c==inf) continue; if((u==a && i==b) || (u==b && i==a)) c = 0; dist[id][i] = min(dist[id][i],dist[id][u]+c); } } // for(int i=1;i<=N;i++) cout << dist[id][i] << endl; } int main(){ cin >> N >> M; int a,b; ll c; for(int i=1;i<=N;i++){ ans[i] = inf; for(int j=1;j<=N;j++){ cost[i][j] = inf; } } for(int i=1;i<=M;i++){ cin >> a >> b >> c; cost[a][b] = c; cost[b][a] = c; } int cnt = 1; dijkstra(0,0,0); for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ if(cost[i][j]!=inf){ dijkstra(cnt,i,j); cnt++; } } } for(int i=1;i<=N;i++){ for(int j=1;j<=cnt-1;j++){ // cerr << dist[0][i] << " " << dist[j][i] << endl; ans[i] = min(ans[i],dist[0][i]+dist[j][i]); } cout << ans[i] << endl; } }