#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll N,M; cin >> N >> M; vector> dist(N, vector (N, 1e18)); rep(i,M){ int s,t; ll d; cin >> s >> t >> d; s--; t--; dist[s][t] = min(dist[s][t], d); } rep(i,N) dist[i][i] = 0; rep(k,N)rep(i,N)rep(j,N){ if(dist[i][k] == 1e18 || dist[k][j] == 1e18) continue; dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } rep(i,N)rep(j,N) if(dist[i][j] == 1e18) dist[i][j] = 0; rep(i,N){ ll ans = 0; rep(j,N) ans += dist[i][j]; cout << ans << '\n'; } }