#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<ctime>
#define maxn 100010
#ifdef WIN32
#define PLL "%I64d"
#else
#define PLL "%lld"
#endif
using namespace std;
int n,m,num,head[maxn],mx,mn=0x7fffffff,cnt;
bool vis[maxn];
struct node{
int to,pre,v;
}e[200010*2];
void Insert(int from,int to,int v){
e[++num].to=to;
e[num].v=v;
e[num].pre=head[from];
head[from]=num;
}
int q[maxn],h,t;
int res;
bool flag=0,com[maxn];
int bfs(int limit){
h=1;
while(h<=t){
int now=q[h];h++;
if(com[now])continue;
flag=0;
for(int i=head[now];i;i=e[i].pre){
if(e[i].v<limit){
flag=1;
continue;
}
int to=e[i].to;
if(!vis[to]){
res++;
vis[to]=1;
q[t++]=to;
}
}
if(flag==0)com[now]=1;
}
return res;
}
int qread(){
int i=0,j=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')j=-1;ch=getchar();}
while(ch<='9'&&ch>='0')i=i*10+ch-'0',ch=getchar();
return i*j;
}
int main(){
// freopen("Cola.txt","r",stdin);
freopen("car.in","r",stdin);freopen("car.out","w",stdout);
n=qread();m=qread();
int x,y,z;
for(int i=1;i<=m;i++){
x=qread();y=qread();z=qread();
Insert(x,y,z);Insert(y,x,z);
mx=max(mx,z);mn=min(mn,z);
}
long long ans;
for(int i=1;i<=n;i++){
ans=0;
memset(q,0,sizeof(q));h=t=1;
memset(vis,0,sizeof(vis));
memset(com,0,sizeof(com));
q[t++]=i;vis[i]=1;
res=0;
int p,now;
for(int j=mx+1;j>=mn-1;j--){
if(j<0)break;
now=bfs(j);
if(j==mx+1){p=now;continue;}
ans+=1LL*(p-now)*(p-now);
p=now;
}
printf(PLL" ",ans);
}
// cout<<endl<<clock();
}