#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = (ll)1e9 + 7; signed main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N >> M; vector>d(N, vector(N, INF)); for (int i = 0; i < N; i++) { d[i][i] = 0; } for (int i = 0; i < M; i++) { ll s, t, c; cin >> s >> t >> c; s--; t--; d[s][t] = min(d[s][t], c); } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for (int i = 0; i < N; i++) { ll ans = 0; for (int j = 0; j < N; j++) { if (d[i][j] >= INF / 3 || i == j)continue; ans += d[i][j]; } cout << ans << endl; } return 0; }