#include<bits/stdc++.h>
using ll=long long;
#define MAXN 70005
struct Edge{
int v; ll w;
int nxt;
};
struct Node{
ll d,c,s;
friend bool operator<(Node a,Node b#include<bits/stdc++.h>
#define int long long
using ll=long long;
#define MAXN 70005
struct Edge{
int v; ll w;
int nxt;
};
struct Node{
ll d,c,s;
friend bool operator<(Node a,Node b){
return a.d>b.d;
}
};
int n,x,y; ll w,k;
Edge e[MAXN*2]; int h[MAXN],ec;
int del[MAXN],sz[MAXN];
ll dep[MAXN];
ll ans[MAXN];
Node q[MAXN],all[MAXN]; int atp,qtp;
int f[MAXN][20]; ll d[MAXN][20];
int cnt[MAXN];
void add(int u,int v,ll w){
e[ec].v=v,e[ec].w=w; e[ec].nxt=h[u];
h[u]=ec; ec++;
return;
}
int getsz(int u,int fa){
sz[u]=1;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
sz[u]+=getsz(v,u);
}
return sz[u];
}
int getrt(int u,int fa,int asz){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
if(sz[v]>asz/2) return getrt(v,u,asz);
}
return u;
}
void getdep(int u,int fa){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
dep[v]=dep[u]+e[i].w; getdep(v,u);
}
return;
}
void clear(int u,int fa){
for(int i=0;i<=17;i++) f[u][i]=d[u][i]=0;
cnt[u]=0;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
clear(v,u);
}
return;
}
void dfs(int u,int fa,int rt,int osz){
for(int i=1;i<=17;i++){
f[u][i]=f[f[u][i-1]][i-1];
d[u][i]=d[f[u][i-1]][i-1]+d[u][i-1];
}
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
f[v][0]=u; d[v][0]=e[i].w;
dfs(v,u,rt,osz);
}
ll t=k; int now=u;
cnt[u]++;
for(int i=17;i>=0;i--){
if(f[now][i]&&d[now][i]<=t) now=f[now][i],t-=d[now][i];
}
if(now==rt){
q[++qtp].d=dep[u];
q[qtp].c=cnt[u];
}else{
ans[now]+=cnt[u]*osz;
cnt[now]+=cnt[u];
}
return;
}
void calc(int u,int fa,int l,int r,ll val){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
int nl=l-1,nr=r;
while(nl<nr){
int mid=(nl+nr+1)>>1;
if(q[mid].d+dep[v]>k){
nl=mid;
}else{
nr=mid-1;
}
}
q[r+1].c=q[nl].s-q[l-1].s;
q[r+1].d=-dep[u];
q[r+1].s=q[r].s+q[r+1].c;
ans[u]+=(long long)q[r+1].c*sz[v]*val;
calc(v,u,nl+1,r+1,val);
}
return;
}
void solve(int u){
del[u]=1; dep[u]=0;
f[u][0]=0; d[u][0]=0;
getsz(u,0),getdep(u,0);
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(del[v]) continue;
f[v][0]=u; d[v][0]=e[i].w;
dfs(v,u,u,sz[u]-sz[v]);
std::sort(q+1,q+qtp+1);
for(int i=1;i<=qtp;i++){
q[i].s=q[i-1].s+q[i].c;
}
ll w=e[i].w;
int l=1,r=qtp;
int nl=l-1,nr=r;
while(nl<nr){
int mid=(nl+nr+1)>>1;
if(q[mid].d+dep[v]>k){
nl=mid;
}else{
nr=mid-1;
}
}
q[r+1].c=q[nl].s-q[l-1].s;
q[r+1].d=-dep[u];
q[r+1].s=q[r].s+q[r+1].c;
ans[u]-=(long long)q[r+1].c*sz[v];
calc(v,u,nl+1,r+1,-1);
for(int i=1;i<=qtp;i++){
all[++atp]=q[i];
}
qtp=0;
}
for(int i=1;i<=atp;i++){
q[i]=all[i];
}
std::sort(q+1,q+atp+1);
if(atp&&q[atp].d==0) q[atp].c++;
else q[++atp].d=0,q[atp].c=1;
for(int i=1;i<=atp;i++){
q[i].s=q[i-1].s+q[i].c;
}
calc(u,0,1,atp,1);
clear(u,0); atp=0;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(del[v]) continue;
solve(getrt(v,u,getsz(v,u)));
}
return;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0),std::cout.tie(0);
memset(h,-1,sizeof(h));
std::cin>>n>>k;
for(int i=1;i<=n-1;i++)
std::cin>>x>>y>>w,x++,y++,add(x,y,w),add(y,x,w);
solve(getrt(1,0,getsz(1,0)));
for(int i=1;i<=n;i++) std::cout<<ans[i]<<'\n';
return 0;
}
return a.d>b.d;
}
};
int n,x,y; ll w,k;
Edge e[MAXN*2]; int h[MAXN],ec;
int del[MAXN],sz[MAXN];
ll dep[MAXN];
ll ans[MAXN];
Node q[MAXN],all[MAXN]; int atp,qtp;
int f[MAXN][20]; ll d[MAXN][20];
int cnt[MAXN];
void add(int u,int v,ll w){
e[ec].v=v,e[ec].w=w; e[ec].nxt=h[u];
h[u]=ec; ec++;
return;
}
int getsz(int u,int fa){
sz[u]=1;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
sz[u]+=getsz(v,u);
}
return sz[u];
}
int getrt(int u,int fa,int asz){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
if(sz[v]>asz/2) return getrt(v,u,asz);
}
return u;
}
void getdep(int u,int fa){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
dep[v]=dep[u]+e[i].w; getdep(v,u);
}
return;
}
void clear(int u,int fa){
for(int i=0;i<=17;i++) f[u][i]=d[u][i]=0;
cnt[u]=0;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
clear(v,u);
}
return;
}
void dfs(int u,int fa,int rt,int osz){
for(int i=1;i<=17;i++){
f[u][i]=f[f[u][i-1]][i-1];
d[u][i]=d[f[u][i-1]][i-1]+d[u][i-1];
}
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
f[v][0]=u; d[v][0]=e[i].w;
dfs(v,u,rt,osz);
}
ll t=k; int now=u;
cnt[u]++;
for(int i=17;i>=0;i--){
if(f[now][i]&&d[now][i]<=t) now=f[now][i],t-=d[now][i];
}
if(now==rt){
q[++qtp].d=dep[u];
q[qtp].c=cnt[u];
}else{
ans[now]+=cnt[u]*osz;
cnt[now]+=cnt[u];
}
return;
}
void calc(int u,int fa,int l,int r,ll val){
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(v==fa||del[v]) continue;
int nl=l-1,nr=r;
while(nl<nr){
int mid=(nl+nr+1)>>1;
if(q[mid].d+dep[v]>k){
nl=mid;
}else{
nr=mid-1;
}
}
q[r+1].c=q[nl].s-q[l-1].s;
q[r+1].d=-dep[u];
q[r+1].s=q[r].s+q[r+1].c;
ans[u]+=(long long)q[r+1].c*sz[v]*val;
calc(v,u,nl+1,r+1,val);
}
return;
}
void solve(int u){
del[u]=1; dep[u]=0;
f[u][0]=0; d[u][0]=0;
getsz(u,0),getdep(u,0);
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(del[v]) continue;
f[v][0]=u; d[v][0]=e[i].w;
dfs(v,u,u,sz[u]-sz[v]);
std::sort(q+1,q+qtp+1);
for(int i=1;i<=qtp;i++){
q[i].s=q[i-1].s+q[i].c;
}
ll w=e[i].w;
int l=1,r=qtp;
int nl=l-1,nr=r;
while(nl<nr){
int mid=(nl+nr+1)>>1;
if(q[mid].d+dep[v]>k){
nl=mid;
}else{
nr=mid-1;
}
}
q[r+1].c=q[nl].s-q[l-1].s;
q[r+1].d=-dep[u];
q[r+1].s=q[r].s+q[r+1].c;
ans[u]-=(long long)q[r+1].c*sz[v];
calc(v,u,nl+1,r+1,-1);
for(int i=1;i<=qtp;i++){
all[++atp]=q[i];
}
qtp=0;
}
for(int i=1;i<=atp;i++){
q[i]=all[i];
}
std::sort(q+1,q+atp+1);
if(atp&&q[atp].d==0) q[atp].c++;
else q[++atp].d=0,q[atp].c=1;
for(int i=1;i<=atp;i++){
q[i].s=q[i-1].s+q[i].c;
}
calc(u,0,1,atp,1);
clear(u,0); atp=0;
for(int i=h[u];i+1;i=e[i].nxt){
int v=e[i].v; if(del[v]) continue;
solve(getrt(v,u,getsz(v,u)));
}
return;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0),std::cout.tie(0);
memset(h,-1,sizeof(h));
std::cin>>n>>k;
for(int i=1;i<=n-1;i++)
std::cin>>x>>y>>w,x++,y++,add(x,y,w),add(y,x,w);
solve(getrt(1,0,getsz(1,0)));
for(int i=1;i<=n;i++) std::cout<<ans[i]<<'\n';
return 0;
}