#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,W;
int pr[125];
vector<pii> g[125];
int sz[125];
int hchild[125];

bool used[125];

int szdfs(int p, int bef){
    sz[p] = 1;
    hchild[p] = -1;
    for(pii P : g[p]){
        int to = P.first;
        if(to==bef)continue;
        if(used[to])continue;
        int ss = szdfs(to,p);
        sz[p] += ss;
        if(hchild[p]==-1 || ss > sz[hchild[p]]){
            hchild[p] = to;
        }
    }
    return sz[p];
}
int r,root;
void grdfs(int p, int bef){
    int x = sz[root] - sz[p];
    for(pii P : g[p]){
        int to = P.first;
        if(to==bef)continue;
        if(used[to])continue;
        grdfs(to,p);
        CHMAX(x, sz[to]);
    }
    if(2*x <= sz[root]){
        r = p;
    }
}

ll answer = 0;

vl dfs(int p, int bef, int w, vl X){
    if(sz[p]==1){
        int s = X.size();
        int ns = min(W,s-1+w);
        vl ret(ns+1,0);
        REP(i,s)if(i+w<=ns)ret[i+w] = X[i]+pr[p];
        return ret;
    }else{
        vl ret = X;
        for(pii P : g[p]){
            int to = P.first;
            if(to==bef)continue;
            if(used[to])continue;
            int nw = P.second;
            vl V = dfs(to,p,nw,ret);
            while(ret.size() < V.size())ret.push_back(0);
            REP(i,ret.size())CHMAX(ret[i], V[i]);
        }
        int s = ret.size();
        int ns = min(W,s-1+w);
        vl tret(ns+1,0);
        REP(i,s)if(i+w<=ns)tret[i+w] = ret[i]+pr[p];
        return tret;
    }
}

void ddfs(int p, int bef){
    szdfs(p,bef);
    root=p; r = p;
    grdfs(p,bef);
    vl init(1,0);
    vl ans = dfs(r,-1,0,init);
    used[r] = true;
    CHMAX(answer, *max_element(ALL(ans)));
    for(pii P : g[r]){
        int to = P.first;
        if(to==bef)continue;
        if(used[to])continue;
        ddfs(to,r);
    }
}

int main(){
    scanf("%d%d",&n,&W);
    REP(i,n)scanf("%d",pr+i);
    REP(i,n-1){
        int u,v,c;
        scanf("%d%d%d",&u,&v,&c);
        --u; --v;
        g[u].push_back(pii(v,c));
        g[v].push_back(pii(u,c));
    }
    REP(i,n)CHMAX(answer, (ll)pr[i]);
    // int root = 0;
    // szdfs(root,-1);
    ddfs(0,-1);
    printf("%lld\n", answer);
    return 0;
}

