#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const LL INF=1000000000000000000; int N,M; LL D[100][100]; int main(){ scanf("%d%d",&N,&M); rep(i,N) rep(j,N) D[i][j]=INF; rep(i,N) D[i][i]=0; rep(i,M){ int u,v; LL d; scanf("%d%d%lld",&u,&v,&d); u--; v--; D[u][v]=min(D[u][v],d); } rep(i,N) rep(j,N) rep(k,N) D[j][k]=min(D[j][k],D[j][i]+D[i][k]); rep(i,N){ LL ans=0; rep(j,N) if(D[i][j]>INF/2) ans+=D[i][j]; printf("%lld\n",ans); } return 0; }