#include #include #include using namespace std; typedef long long ll; const ll INF = 1e+15; typedef pair P; struct edge{ int to; ll cost; }; void dijkstra(int s, int num_v, vector G[], ll d[]){ priority_queue, greater

> que; fill(d, d+num_v, INF); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top();que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if(d[v] + e.cost < d[e.to]){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } vector G[200000]; ll dist[200000]; int main(){ int N, M; cin >> N >> M; for(int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back((edge){b, c}); G[a+N].push_back((edge){b+N, c}); G[a].push_back((edge){b+N, 0}); G[b].push_back((edge){a, c}); G[b+N].push_back((edge){a+N, c}); G[b].push_back((edge){a+N, 0}); } dijkstra(0, N*2, G, dist); cout << 0 << endl; for(int i = 1; i < N; i++){ cout << dist[i]+dist[i+N] << endl; } }