import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int m = Integer.parseInt(sa[1]); long inf = 1000000000000000000L; long[][] d = new long[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { d[i][j] = inf; } } } for (int i = 0; i < m; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; long c = Long.parseLong(sa[2]); d[a][b] = Math.min(d[a][b], c); } br.close(); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (d[i][k] != inf && d[k][j] != inf) { d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]); } } } } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < n; i++) { long ans = 0; for (int j = 0; j < n; j++) { if (d[i][j] != inf) { ans += d[i][j]; } } pw.println(ans); } pw.flush(); } }