#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; typedef ll Weight; struct Edge { int from, to; Weight wei; Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {} }; typedef vector Edges; typedef vector Graph; const Weight INFW = numeric_limits::max(); vector dijkstra(const Graph &G, int src) { typedef pair pwi; priority_queue, greater> pq; pq.push(mp(0, src)); int V = (int)G.size(); vector res(V, -1); while (pq.size()) { auto p = pq.top(); pq.pop(); Weight d = p.first; int v = p.second; if (res[v] > -1)continue; res[v] = d; for (const auto &edge : G[v]) { int to = edge.to; Weight wei = edge.wei; pq.push(make_pair(d + wei, to)); } } return res; } void solve() { int N, M; cin >> N >> M; Graph G(2*N); rep(i, M) { int a, b, c; cin >> a >> b >> c; --a; --b; G[a].emplace_back(a, b, c); G[b].emplace_back(b, a, c); G[a + N].emplace_back(a + N, b + N, c); G[b + N].emplace_back(b + N, a + N, c); G[a].emplace_back(a, b + N, 0); G[b].emplace_back(b, a + N, 0); } auto D = dijkstra(G, 0); cout << 0 << endl; FOR(i, 1, N) { cout << D[i] + D[i + N] << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }