import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long[][] costs = new long[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(costs[i], Long.MAX_VALUE / 2); costs[i][i] = 0; } for (int i = 0; i < m; i++) { int left = sc.nextInt() - 1; int right = sc.nextInt() - 1; long v = sc.nextLong(); costs[left][right] = Math.min(costs[left][right], v); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (costs[j][i] < Long.MAX_VALUE / 2 && costs[i][k] < Long.MAX_VALUE / 2) { costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]); } } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { long sum = 0; for (long x : costs[i]) { if (x < Long.MAX_VALUE / 2) { sum += x; } } sb.append(sum).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }