#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr ll INF = 1002003004005006007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    VVL dist(n, VL(n, INF));
    rep(i, n) dist[i][i] = 0;
    rep(_, m) {
        int s, t;
        ll d;
        cin >> s >> t >> d;
        --s, --t;
        chmin(dist[s][t], d);
    }
    rep(k, n) rep(i, n) rep(j, n) {
        if (dist[i][k] != INF && dist[k][j] != INF) chmin(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 s = 0;
        rep(j, n) s += dist[i][j];
        cout << s << '\n';
    }
}