#include using namespace std; #define REP(i,N) for(i=0;i P; typedef struct{ int first; int second; int third; }T; //昇順 bool comp_Se(T& l, T& r){ return l.second < r.second; } int N,M; vector< vector > cost; vector > d; vector used; vector ticket; void dijkstra(){ while(true){ int v = -1; //まだ使われていない頂点のうち距離が最小のものを探す for(int u = 0; u < N; u++){ if(!used[u] && (v == -1 || d[u].first < d[v].first) ) v = u; } if( v == -1) break; used[v] = true; for(int u = 0; u < N; u++){ if(cost[u][v] != INF){ d[u].first = min(d[u].first, d[v].first+cost[v][u]); d[u].second = min(d[u].second, d[v].second + min(ticket[v],cost[u][v])); ticket[u] = max(ticket[v],cost[u][v]); } } } } int main(void){ cin >> N >> M; cost = vector >(M, vector(M, INF)); d = vector >(N,pair(INF,INF)); d[0] = pair(0,0); used = vector(M,false); ticket = vector(M,0); int i; REP(i,M){ int x,y,z; cin >> x >> y >> z; cost[x-1][y-1] = z; cost[y-1][x-1] = z; } dijkstra(); REP(i,N){ cout << d[i].first+d[i].second << endl; } return 0; }