#include using namespace std; using vi = vector ;using vl = vector ; using vs = vector ;using vc = vector ; using ll= long long;using vvl = vector >; using vvc = vector >;using vd = vector ; using vpl = vector >;using vb = vector; #define rep(i,r) for(ll i=0;i<(r);i++) #define Rep(i,l,r) for(ll i=(l);i<(r);i++) #define print(n) cout<>a[i] #define sortp(d) sort(d.begin(),d.end()) //1234 #define sortm(d) sort(d.rbegin(),d.rend()) //4321 #define all(n) n.begin(),n.end() //各位の和  int wa(ll x){ll sum=0;while(x!=0){sum+=x%10;x/=10;}return sum;} /*-----------順列生成----------------- do { } while (next_permutation(配列変数.begin(), 配列変数.end()));*/ //最大公約数 ユークリッドの互除法 ll gcd(ll a, ll b) {if (b==0) return a;else return gcd(b, a%b);} //最小公倍数 a*b/gcd ll lcm(ll a,ll b){return a/gcd(a,b)*b;} //'A'65,'a'97 /*小数点精度指定 cout<0) {if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;} ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);} ll p=0,q=0,r=0; int dx[8]={1,0,-1,0,1,-1,-1,1};int dy[8]={0,1,0,-1,1,1,-1,-1}; #define inf 1000000000000 //10^12:∞ #define mod 1000000007 //10^9+7:合同式の法 const long double pi = acos(-1); int main() { ll n,m;cin>>n>>m; vvl v(n,vl(n,inf)); rep(i,m) { ll s,t,d;cin>>s>>t>>d; s--;t--; if(v[s][t]==inf)v[s][t]=d; else v[s][t]+=d; } rep(k,n)rep(i,n)rep(j,n) if(i==j)v[i][j]=0;else v[i][j]=min(v[i][j],v[i][k]+v[k][j]); rep(i,n) { p=0; rep(j,n)if(v[i][j]!=inf)p+=v[i][j]; print(p); } }