#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, m; cin >> n >> m; constexpr ll INF = 1e18; vector dist(n, vector(n, INF)); rep(_, m) { int a, b; ll c; cin >> a >> b >> c; --a, --b; dist[a][b] = min(dist[a][b], c); } rep(i, n) dist[i][i] = 0; rep(k, n) rep(i, n) rep(j, n) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } rep(i, n) rep(j, n) if (dist[i][j] == INF) dist[i][j] = 0; rep(i, n) { ll ans = 0; rep(j, n) ans += dist[i][j]; cout << ans << '\n'; } return 0; }