#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;
int n, k;
const int maxn = 1e4+10;
int ans;
struct Edge{
int to;
int length;
};
vector<Edge> G[maxn];
int sub_tree_size[maxn];
bool centroid[maxn];
int cal_subtree_number(int u, int p){
int c = 1;
for(int i=0; i<G[u].size(); i++){
int v = G[u][i].to;
if(v == p || centroid[v]) continue;
c += cal_subtree_number(v, u);
}
sub_tree_size[u] = c;
return c;
}
pair<int, int> find_centroid(int u, int p, int tot_number){
int m = 0, number = 1;
pair<int, int> res = make_pair(INT_MAX, -1);
for(int i=0; i<G[u].size(); i++){
int v = G[u][i].to;
if(v == p || centroid[v])continue;
res = min(res, find_centroid(v, u, tot_number));
number += sub_tree_size[v];
m = max(m, sub_tree_size[v]);
}
m = max(m, tot_number-number);
res = min(res, make_pair(m, u));
return res;
}
void enumerate_path(int u, int p, int length, vector<int>& ds){
ds.push_back(length);
for(int i=0; i<G[u].size(); i++){
int v = G[u][i].to;
if(centroid[v] || v == p) continue;
enumerate_path(v, u, length+G[u][i].length, ds);
}
return ;
}
int count_pair(vector<int>& ds){
int ans1 = 0;
sort(ds.begin(), ds.end());
int j = ds.size();
for(int i=0; i<ds.size(); i++){
while(j>0&&ds[i]+ds[j-1]>k) j--;
if(j>i) ans1 += (j-1);
else ans1 += j;
}
return ans1/2;
}
void sub_problem(int u){
cal_subtree_number(u, -1);
int s = find_centroid(u, -1, sub_tree_size[u]).second;
centroid[s] = true;
for(int i=0; i<G[s].size(); i++){
int v = G[s][i].to;
if(centroid[v]) continue;
sub_problem(v);
}
vector<int> ds;
ds.clear();
ds.push_back(0);
for(int i=0; i<G[s].size(); i++){
vector<int> tds;
tds.clear();
int v = G[s][i].to;
if(centroid[v])continue;
enumerate_path(v, s, G[s][i].length, tds);
ans -= count_pair(tds);
ds.insert(ds.end(), tds.begin(), tds.end());
}
ans += count_pair(ds);
centroid[s] = false;
}
void solve(int s){
ans = 0;
memset(centroid, false, sizeof(centroid));
sub_problem(s);
printf("%d\n", ans);
}
int main()
{
while(~scanf("%d%d", &n, &k)&&(n+k)){
int a, b, length;
for(int i=0; i<n; i++){
G[i].clear();
}
for(int i=0; i<n-1; i++){
scanf("%d%d%d", &a, &b, &length);
Edge temp;
temp.to = b-1, temp.length = length;
G[a-1].push_back(temp);
temp.to = a-1;
G[b-1].push_back(temp);
}
solve(a-1);
}
return 0;
}