#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int MAXN=7e4+10;
int n, m;
vector<int>graph[MAXN], weight[MAXN], resp(MAXN, 0), subsz(MAXN);
int find_subsz(int x, int p){
int aux=1;
for(int k=0;k<graph[x].size();k++){
int neighbour=graph[x][k];
if(neighbour!=p){
aux+=find_subsz(neighbour, x);
}
}
subsz[x]=aux;
return subsz[x];
}
void dfs(int x, int p, int tank){
for(int k=0;k<graph[x].size();k++){
int neighbour=graph[x][k], w=weight[x][k];
if(neighbour!=p){
if(tank<w){
resp[x]+=subsz[neighbour];
dfs(neighbour, x, m-w);
}else{
dfs(neighbour, x, tank-w);
}
}
}
}
int32_t main(){
cin>>n>>m;
for(int k=1;k<n;k++){
int a, b, w;
cin>>a>>b>>w;
graph[a].push_back(b);
graph[b].push_back(a);
weight[a].push_back(w);
weight[b].push_back(w);
}
for(int k=0;k<n;k++){
find_subsz(k, -1);
dfs(k, -1, m);
}
for(int k=0;k<n;k++){
cout<<resp[k]<<endl;
}
}