from scipy.sparse.csgraph import shortest_path, johnson from scipy.sparse import csr_matrix import numpy as np n,m=map(int,input().split()) a=[[10**18]*n for _ in range(n)] for i in range(m): s,t,d=map(int,input().split()) a[s-1][t-1]=min(a[s-1][t-1],d) a = np.array(a) ans=shortest_path(a,method="J") for i in range(n): m=0 for j in range(n): if ans[i][j]>=10**15: m+=0 else: m+=int(ans[i][j]) print(m)