using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = ((int)c[0], (int)c[1]); var map = NArr(m); var INF = long.MaxValue / 3; var wf = new long[n][]; for (var i = 0; i < n; ++i) { wf[i] = Enumerable.Repeat(INF, n).ToArray(); wf[i][i] = 0; } foreach (var edge in map) { wf[edge[0] - 1][edge[1] - 1] = Math.Min(wf[edge[0] - 1][edge[1] - 1], edge[2]); } for (var k = 0; k < n; ++k) for (var i = 0; i < n; ++i) for (var j = 0; j < n; ++j) { wf[i][j] = Math.Min(wf[i][j], wf[i][k] + wf[k][j]); } var ans = new long[n]; for (var i = 0; i < n; ++i) for (var j = 0; j < n; ++j) if (wf[i][j] < INF) ans[i] += wf[i][j]; WriteLine(string.Join("\n", ans)); } }