import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; 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]); List> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } 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]); list.get(a).add(new Hen(b, c)); } br.close(); for (int i = 0; i < n; i++) { long[] d = dijkstra(list, i); long ans = 0; for (int j = 0; j < n; j++) { if (d[j] != Long.MAX_VALUE) { ans += d[j]; } } System.out.println(ans); } } static long[] dijkstra(List> list, int s) { long[] d = new long[list.size()]; Arrays.fill(d, Long.MAX_VALUE); d[s] = 0; PriorityQueue que = new PriorityQueue(); Node first = new Node(s, 0); que.add(first); while (!que.isEmpty()) { Node cur = que.poll(); if (cur.d > d[cur.v]) { continue; } for (Hen hen : list.get(cur.v)) { long alt = d[cur.v] + hen.c; if (alt < d[hen.v]) { d[hen.v] = alt; que.add(new Node(hen.v, alt)); } } } return d; } static class Hen { int v; long c; public Hen(int v, long c) { this.v = v; this.c = c; } } static class Node implements Comparable { int v; long d; public Node(int v, long d) { this.v = v; this.d = d; } public int compareTo(Node o) { return Long.compare(d, o.d); } } }