#include using namespace std; using edge = pair; using Graph = vector>; template inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;} template inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;} const long long INF = 1e12; vector dijkstra(const Graph &g, int s) { vector dist(g.size(), INF); using Pi = pair; priority_queue, greater> que; dist[s] = 0; que.emplace(dist[s], s); while (!que.empty()) { long long cost; int u; tie(cost, u) = que.top(); que.pop(); if (dist[u] < cost) continue; for (auto &e: g[u]) { int v; long long nc; tie(v, nc) = e; if (chmin(dist[v], dist[u] + nc)) que.emplace(dist[v], v); } } return dist; } int main(){ int N, M; cin >> N >> M; Graph G(N, vector()); Graph H(2 * N, vector()); for (int i = 0; i < M; i++) { int a, b; long long c; cin >> a >> b >> c; a--; b--; G[a].push_back(make_pair(b, c)); G[b].push_back(make_pair(a, c)); H[a].push_back(make_pair(b, c)); H[b].push_back(make_pair(a, c)); H[N + a].push_back(make_pair(N + b, c)); H[N + b].push_back(make_pair(N + a, c)); H[a].push_back(make_pair(N + b, 0LL)); H[b].push_back(make_pair(N + a, 0LL)); } vector time2 = dijkstra(H, 0); for (int i = 0; i < N; i++) { cout << time2[i] + time2[i + N] << endl; } return 0; }