#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cassert>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int SIZE=10000;

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

int N,K;
vector<edge>G[SIZE];

bool centroid[SIZE];
int subtree_size[SIZE];

int ans;

int compute_subtree_size(int v,int p){
    int c=1;
    rep(i,G[v].size()){
        int to=G[v][i].to;
        if(to==p||centroid[to])continue;
        c+=compute_subtree_size(to,v);
    }
    subtree_size[v]=c;
    return c;
}

pint search_centroid(int v,int p,int t){
    pint res=mp(INT_MAX,-1);
    int s=1,m=0;
    rep(i,G[v].size()){
        int to=G[v][i].to;
        if(to==p||centroid[to])continue;
        res=min(res,search_centroid(to,v,t));
        m=max(m,subtree_size[to]);
        s+=subtree_size[to];
    }

    m=max(m,t-s);
    res=min(res,mp(m,v));
    return res;
}

void enumerate_paths(int v,int p,int d,vint &ds){
    ds.pb(d);
    rep(i,G[v].size()){
        int to=G[v][i].to;
        if(to==p||centroid[to])continue;
        enumerate_paths(to,v,d+G[v][i].cost,ds);
    }
}

int count_pairs(vint &ds){
    int res=0;
    sort(ds.begin(),ds.end());
    int j=ds.size();
    rep(i,ds.size()){
        while(j>0&&ds[i]+ds[j-1]>K)j--;
        res+=j-(j>i?1:0);
    }
    return res/2;
}

void solve_subproblem(int v){
    compute_subtree_size(v,-1);
    int s=search_centroid(v,-1,subtree_size[v]).second;
    centroid[s]=true;

    rep(i,G[s].size()){
        if(centroid[G[s][i].to])continue;
        solve_subproblem(G[s][i].to);
    }

    vint ds;
    ds.pb(0);
    rep(i,G[s].size()){
        if(centroid[G[s][i].to])continue;
        vint tds;
        enumerate_paths(G[s][i].to,s,G[s][i].cost,tds);

        ans-=count_pairs(tds);
        ds.insert(ds.end(),tds.begin(),tds.end());
    }

    ans+=count_pairs(ds);
    centroid[s]=false;
}

int main(){

    while(scanf("%d%d",&N,&K),N||K){
        rep(i,N)G[i].clear();
        ans=0;

        rep(i,N-1){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            a--;b--;
            G[a].pb(edge(b,c));
            G[b].pb(edge(a,c));
        }

        solve_subproblem(0);
        printf("%d\n",ans);
    }

    return 0;
}