#include using namespace std; const long long INF = 1000000000000000; int main(){ int N, M; cin >> N >> M; vector> E(N, vector(N, INF)); for (int i = 0; i < N; i++){ E[i][i] = 0; } for (int i = 0; i < M; i++){ int s, t; long long d; cin >> s >> t >> d; s--; t--; E[s][t] = d; } for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ for (int k = 0; k < N; k++){ E[j][k] = min(E[j][k], E[j][i] + E[i][k]); } } } for (int i = 0; i < N; i++){ long long ans = 0; for (int j = 0; j < N; j++){ if (E[i][j] <= INF / 2){ ans += E[i][j]; } } cout << ans << endl; } }