import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); 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 / 10); costs[i][i] = 0; } for (int i = 0; i < m; i++) { int left = sc.nextInt() - 1; int right = sc.nextInt() - 1; long value = sc.nextLong(); costs[left][right] = Math.min(costs[left][right], value); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { 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 ans = 0; for (int j = 0; j < n; j++) { if (costs[i][j] < Long.MAX_VALUE / 10) { ans += costs[i][j]; } } sb.append(ans).append("\n"); } System.out.print(sb); } }