#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); const ll INF = 1ll << 60; int N, M; cin >> N >> M; vector dp(N, vector(N, INF)); rep(i, 0, M) { int s, t; ll d; cin >> s >> t >> d; --s, --t; dp[s][t] = min(dp[s][t], d); } rep(i, 0, N) dp[i][i] = 0; rep(k, 0, N) { rep(i, 0, N) rep(j, 0, N) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); } rep(i, 0, N) { ll ans = 0; rep(j, 0, N) { if (dp[i][j] != INF) ans += dp[i][j]; } cout << ans << '\n'; } }