import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.TreeMap; import java.util.TreeSet; 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; TreeMap map = new TreeMap<>(); TreeSet que = new TreeSet(); Node first = new Node(s, 0); que.add(first); map.put(s, first); while (!que.isEmpty()) { Node cur = que.pollFirst(); map.remove(cur.v); for (Hen hen : list.get(cur.v)) { long alt = d[cur.v] + hen.c; if (alt < d[hen.v]) { d[hen.v] = alt; Node next = new Node(hen.v, alt); if (map.containsKey(hen.v)) { que.remove(map.get(hen.v)); } que.add(next); map.put(hen.v, next); } } } 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) { if (d != o.d) { return Long.compare(d, o.d); } return v - o.v; } } }