#include #define int long long #define FOR(i, a, b) for (int i = a; i < b; ++i) #define rep(N) for (int i = 0; i < N; ++i) #define Rep(a, b) for (int i = a; i < b; ++i) #define For(i, N) for (int i = 0; i < N; ++i) #define all(v) v.begin(), v.end() #define rev(v) v.rbegin(), v.rend() #define makei(N) int N; cin >> N; #define makes(s) string s; cin >> s; #define maked(d) double d; cin >> d; #define makev(v, N) vi v(N); rep(N)cin >> v[i]; #define mod 1000000007 using namespace std; using ll = long long; using vi = vector; using vvi = vector>; using vll = vector; using vb = vector; using vvb = vector>; using vs = vector; using pii = pair; using pis = pair; using msi = map; template void say(T s) { cout << s << "\n"; } template void say(vector s) { auto itr = s.begin(); cout << *(itr++); while (itr != s.end()) { cout << " " << *(itr++); } cout << "\n"; } template void say(vector s, char r) { auto itr = s.begin(); cout << *(itr++); while (itr != s.end()) { cout << r << *(itr++); } cout << "\n"; } void yn(bool b) { if (b)say("yes"); else say("no"); } void Yn(bool b) { if (b)say("Yes"); else say("No"); } void YN(bool b) { if (b)say("YES"); else say("NO"); } template void maxi(T& a, T b) { a = max(a, b); } template void mini(T& a, T b) { a = min(a, b); } void exact_say(double x) { cout << setprecision(numeric_limits::max_digits10) << x << endl; } template vector> fill_vector(int h, int w, T val) { vector> ret; vector v(w, val); rep(h)ret.push_back(v); return ret; } signed main() { makei(n); makei(m); vi ans(n, INT_MAX); vb used(n, false); vvi g = fill_vector(n, n, (ll)INT_MAX); rep(m) { makei(a); makei(b); makei(c); --a; --b; g[a][b] = c; g[b][a] = c; } ans[0] = 0; used[0] = true; rep(n) { mini(ans[i], ans[0] + g[0][i]); } while (true) { int v = -1; for (int u = 0; u < n; ++u) { if (!used[u] && (v == -1 || ans[u] < ans[v]))v = u; } if (v == -1)break; used[v] = true; rep(n) { mini(ans[i], ans[v] + g[v][i]); } } vi ans2(n, INT_MAX); rep(n)used[i] = false; ans2[0] = 0; used[0] = true; rep(n) { if (g[i][0] < INT_MAX) ans2[i] = 0; } while (true) { int v = -1; for (int u = 0; u < n; ++u) { if (!used[u] && (v == -1 || ans2[u] < ans2[v]))v = u; } if (v == -1)break; used[v] = true; rep(n) { mini(ans2[i], ans2[v] + g[v][i]); if (g[v][i] < INT_MAX)mini(ans2[i], ans[v]); } } rep(n)say(ans[i] + ans2[i]); }