#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, w;
ll p[100];
int sz[100];
vector<pi> e[100];
bool saw[100];

void dfs (int v, int par, vector<ll>& dp) {
    rep(i,e[v].size()) {
        if (e[v][i].first == par) continue;
        if (saw[e[v][i].first]) continue;
        vector<ll> tmp(w+1, -linf);
        for (int j = e[v][i].second; j <= w; j++) {
            tmp[j] = dp[j-e[v][i].second];
        }
        dfs(e[v][i].first, v, tmp);
        rep(j,w+1) dp[j] = max(dp[j], tmp[j]);
    }
    rep(i,w+1) dp[i] += p[v];
}

int calc_sz (int v, int p) {
    sz[v] = 1;
    rep(i,e[v].size()) {
        if (e[v][i].first == p) continue;
        if (saw[e[v][i].first]) continue;
        calc_sz(e[v][i].first, v);
        sz[v] += sz[e[v][i].first];
    }
    return sz[v];
}

int get_cen (int v, int p, int s) {
    rep(i,e[v].size()) {
        if (e[v][i].first == p) continue;
        if (saw[e[v][i].first]) continue;
        if (sz[e[v][i].first]*2 >= s) return get_cen(e[v][i].first, v, s);
    }
    return v;
}

int main() {
    cin >> n >> w;
    rep(i,n) cin >> p[i];
    rep(i,n-1) {
        int u, v, c;
        cin >> u >> v >> c;
        u--; v--;
        e[u].push_back(pi(v,c));
        e[v].push_back(pi(u,c));
    }
    ll ans = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int q = que.front(); que.pop();
        if (saw[q]) continue;
        int s = calc_sz(q, q);
        int c = get_cen(q, q, s);
        rep(i,e[c].size()) {
            if (saw[e[c][i].first]) continue;
            que.push(e[c][i].first);
        }
        vector<ll> dp(w+1, -linf);
        dp[0] = 0;
        dfs(c, c, dp);
        ans = max(ans, *max_element(dp.begin(), dp.end()));
        saw[c] = true;
    }
    cout << ans << endl;
}

