#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF = 1000000000000000; ll dist[101][101]; void warshall_floyd(int v) { for (int k = 1; k <= v; k++) { for (int i = 1; i <= v; i++) { for (int j = 1; j <= v; j++) { if (dist[i][k] == INF) continue; if (dist[k][j] == INF) continue; dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } int main() { int N, M; cin >> N >> M; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { dist[i][j] = INF; } dist[i][i] = 0; } for (int i = 0; i < M; ++i) { int s, t; ll d; cin >> s >> t >> d; dist[s][t] = min(dist[s][t], d); } warshall_floyd(N); for (int s = 1; s <= N; ++s) { ll ans = 0; for (int t = 1; t <= N; ++t) { if (s == t) continue; if (dist[s][t] == INF) continue; ans += dist[s][t]; } cout << ans << endl; } return 0; }