#include "bits/stdc++.h"
#define int long long
using namespace std;
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0);
int N, K; cin >> N >> K;
vector<vector<int>> adj(N + 1);
map<pair<int, int>, int> ed;
for (int i = 0; i < N - 1; i++) {
int a, b, c; cin >> a >> b >> c; a++, b++;
adj[a].push_back(b);
adj[b].push_back(a);
ed[{a, b}] = ed[{b, a}] = c;
}
vector<int> pai(N + 1), dep(N + 1);
auto dfs = [&](auto dfs, int x, int p) -> void {
for (int k : adj[x]) if (k != p) {
pai[k] = x;
dep[k] = dep[x] + 1;
dfs(dfs, k, x);
}
};
dfs(dfs, 1, -1);
vector<int> ans(N + 1);
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) {
if (dep[i] < dep[j]) continue;
vector<int> path = {i};
while (path.back() != j)
path.push_back(pai[path.back()]);
int sum = 0;
for (int k = 0; k < int32_t(size(path)) - 1; k++) {
sum += ed[{path[k], path[k + 1]}];
if (sum > K) {
sum = ed[{path[k], path[k + 1]}];
ans[path[k]]++;
}
}
reverse(path.begin(), path.end());
sum = 0;
for (int k = 0; k < int32_t(size(path)) - 1; k++) {
sum += ed[{path[k], path[k + 1]}];
if (sum > K) {
sum = ed[{path[k], path[k + 1]}];
ans[path[k]]++;
}
}
}
for (int i = 1; i <= N; i++)
cout << ans[i] << '\n';
return 0;
}