import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val m = nextInt() val INF = 1000000000000000000 val dist = Array(n) { Array(n) { INF } } for (i in 0 until m) { val s = nextInt() - 1 val t = nextInt() - 1 val d = nextLong() dist[s][t] = min(dist[s][t], d) } for (k in 0 until n) { for (i in 0 until n) { for (j in 0 until n) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) } } } for (i in 0 until n) { var sum = 0L for (j in 0 until n) { sum += if (i == j || dist[i][j] == INF) 0 else dist[i][j] } println(sum) } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion