#include #include using namespace std; using namespace atcoder; #define ll long long #define rep(i,n) for (int i = 0; i < (n); i++) #define coutf(f) cout << fixed << setprecision(f) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() const ll INF = 1e18; void warshall_floyd(vector> &dist) { int v = dist.size(); for (int k = 0; k < v; k++) { for (int i = 0; i < v; i++) { for (int j = 0; j < v; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } int main() { int n, m; cin >> n >> m; vector> dist(n, vector(n, INF)); rep(i, m) { int s, t; ll d; cin >> s >> t >> d; s--; t--; dist[s][t] = min(dist[s][t], d); } warshall_floyd(dist); map mp; rep(i, n) { rep(j, n) { if (i == j) { dist[i][j] = 0; } if (dist[i][j] == INF / 2) { dist[i][j] = 0; } } } rep(i, n) { rep(j, n) { mp[i] += dist[i][j]; } } for (auto p : mp) cout << p.second << endl; return 0; }