#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#define NDEBUG
#define SHOW(...) static_cast<void>(0)
//!===========================================================!//
//!  dP     dP                          dP                    !//
//!  88     88                          88                    !//
//!  88aaaaa88a .d8888b. .d8888b. .d888b88 .d8888b. 88d888b.  !//
//!  88     88  88ooood8 88'  '88 88'  '88 88ooood8 88'  '88  !//
//!  88     88  88.  ... 88.  .88 88.  .88 88.  ... 88        !//
//!  dP     dP  '88888P' '88888P8 '88888P8 '88888P' dP        !//
//!===========================================================!//
template <typename T>
T read()
{
    T v;
    return std::cin >> v, v;
}
template <typename T>
std::vector<T> readVec(const std::size_t l)
{
    std::vector<T> v(l);
    for (auto& e : v) { std::cin >> e; }
    return v;
}
using ld = long double;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr unsigned int MOD = 1000000007;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 4;
template <typename F>
constexpr F PI = static_cast<F>(3.1415926535897932385);
std::mt19937 mt{std::random_device{}()};
template <typename T>
bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template <typename T>
bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
template <typename T>
std::vector<T> Vec(const std::size_t n, T v) { return std::vector<T>(n, v); }
template <class... Args>
auto Vec(const std::size_t n, Args... args) { return std::vector<decltype(Vec(args...))>(n, Vec(args...)); }
template <typename T>
constexpr T popCount(const T u)
{
#ifdef __has_builtin
    return u == 0 ? T(0) : (T)__builtin_popcountll(u);
#else
    unsigned long long v = static_cast<unsigned long long>(u);
    return v = (v & 0x5555555555555555ULL) + (v >> 1 & 0x5555555555555555ULL), v = (v & 0x3333333333333333ULL) + (v >> 2 & 0x3333333333333333ULL), v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL, static_cast<T>(v * 0x0101010101010101ULL >> 56 & 0x7f);
#endif
}
template <typename T>
constexpr T log2p1(const T u)
{
#ifdef __has_builtin
    return u == 0 ? T(0) : T(64 - __builtin_clzll(u));
#else
    unsigned long long v = static_cast<unsigned long long>(u);
    return v = static_cast<unsigned long long>(v), v |= (v >> 1), v |= (v >> 2), v |= (v >> 4), v |= (v >> 8), v |= (v >> 16), v |= (v >> 32), popCount(v);
#endif
}
template <typename T>
constexpr T clog(const T v) { return v == 0 ? T(0) : log2p1(v - 1); }
template <typename T>
constexpr T msbp1(const T v) { return log2p1(v); }
template <typename T>
constexpr T lsbp1(const T v)
{
#ifdef __has_builtin
    return __builtin_ffsll(v);
#else
    return v == 0 ? T(0) : popCount((v & (-v)) - T(1)) + T(1);
#endif
}
template <typename T>
constexpr bool ispow2(const T v) { return popCount(v) == 1; }
template <typename T>
constexpr T ceil2(const T v) { return v == 0 ? T(1) : T(1) << log2p1(v - 1); }
template <typename T>
constexpr T floor2(const T v) { return v == 0 ? T(0) : T(1) << (log2p1(v) - 1); }
//!=================================================!//
//!   .88888.                             dP        !//
//!  d8'   '88                            88        !//
//!  88        88d888b. .d8888b. 88d888b. 88d888b.  !//
//!  88   YP88 88'  '88 88'  '88 88'  '88 88'  '88  !//
//!  Y8.   .88 88       88.  .88 88.  .88 88    88  !//
//!   '88888'  dP       '88888P8 88Y888P' dP    dP  !//
//!                              88                 !//
//!                              dP                 !//
//!=================================================!//
struct Graph
{
    Graph(const std::size_t v) : V{v}, edge(v), rev_edge(v) {}
    void addEdge(const std::size_t from, const std::size_t to, const bool bi = false)
    {
        assert(from < V), assert(to < V);
        edge[from].push_back(to), rev_edge[to].push_back(from);
        if (bi) { addEdge(to, from, false); }
    }
    const std::vector<std::size_t>& operator[](const std::size_t i) const { return assert(i < V), edge[i]; }
    friend std::ostream& operator<<(std::ostream& os, const Graph& g)
    {
        os << "[\n";
        for (std::size_t i = 0; i < g.V; i++) {
            for (const std::size_t to : g.edge[i]) { os << i << "->" << to << "\n"; }
        }
        return (os << "]\n");
    }
    std::size_t V;
    std::vector<std::vector<std::size_t>> edge, rev_edge;
};
using Tree = Graph;
//!==================================!//
//!  dP     dP  dP        888888ba   !//
//!  88     88  88        88    '8b  !//
//!  88aaaaa88a 88        88     88  !//
//!  88     88  88        88     88  !//
//!  88     88  88        88    .8P  !//
//!  dP     dP  88888888P 8888888P   !//
//!==================================!//
class HLD
{
public:
    HLD(Tree& tree, const std::size_t r = 0) : par(tree.V, tree.V), top(tree.V, tree.V), in(tree.V, tree.V), out(tree.V, tree.V)
    {
        const std::size_t N = tree.V;
        std::vector<std::size_t> sz(N, 1);
        auto dfs1 = [&](auto&& self, const std::size_t s, const std::size_t p) -> std::size_t {
            par[s] = p;
            for (std::size_t& to : tree.edge[s]) {
                if (p == to) { continue; }
                sz[s] += self(self, to, s);
                if (sz[to] > sz[tree.edge[s][0]]) { std::swap(to, tree.edge[s][0]); }
            }
            return sz[s];
        };
        dfs1(dfs1, r, N);
        top[r] = r;
        auto dfs2 = [&](auto&& self, const std::size_t s, const std::size_t p, std::size_t& ind) -> void {
            in[s] = ind++;
            for (const std::size_t to : tree.edge[s]) {
                if (to == p) { continue; }
                top[to] = (to == tree.edge[s][0] ? top[s] : to);
                self(self, to, s, ind);
            }
            out[s] = ind;
        };
        std::size_t ind = 0;
        dfs2(dfs2, r, N, ind);
    }
    std::size_t at(const std::size_t v) const { return in[v]; }
    std::pair<std::size_t, std::size_t> sub(const std::size_t v) const { return {in[v], out[v]}; }
    std::vector<std::pair<std::size_t, std::size_t>> path(std::size_t u, std::size_t v, const bool edgeWeight = false) const
    {
        using P = std::pair<std::size_t, std::size_t>;
        std::vector<P> head, tail;
        for (std::size_t pu = top[u], pv = top[v]; pu != pv;) {
            if (in[pu] < in[pv]) {
                tail.push_back({in[pv], in[v]});
                v = par[pv], pv = top[v];
            } else {
                tail.push_back({in[u], in[pu]});
                u = par[pu], pu = top[u];
            }
        }
        if (edgeWeight) {
            if (std::abs((int)in[u] - (int)in[v]) >= 1) { head.push_back(in[u] < in[v] ? P{in[u] + 1, in[v]} : P{in[u], in[v] + 1}); }
        } else {
            head.push_back({in[u], in[v]});
        }
        std::reverse(tail.begin(), tail.end());
        for (const auto& p : tail) { head.push_back(p); }
        return head;
    }

private:
    std::vector<std::size_t> par, top, in, out;
};
//!=====================================!//
//!  8888ba.88ba           oo           !//
//!  88  '8b  '8b                       !//
//!  88   88   88 .d8888b. dP 88d888b.  !//
//!  88   88   88 88'  '88 88 88'  '88  !//
//!  88   88   88 88.  .88 88 88    88  !//
//!  dP   dP   dP '88888P8 dP dP    dP  !//
//!=====================================!//
int main()
{
    const int N = read<int>(), W = read<int>();
    const auto P = readVec<ll>(N);
    auto C = Vec(N, N, 0);
    Graph T(N);
    for (int i = 0; i < N - 1; i++) {
        const int u = read<int>() - 1, v = read<int>() - 1, c = read<int>();
        T.addEdge(u, v, true), C[u][v] = C[v][u] = c;
    }
    HLD hld(T, 0);
    ll ans = 0;
    std::vector<ll> init(W + 1, -INF<ll>);
    init[0] = 0;
    auto RecDP = [&, N, W](auto&& self, const int s, const int prev, const bool empty, const std::vector<ll>& X) -> std::vector<ll> {
        auto Xs = X;
        for (int i = 0; i < T[s].size(); i++) {
            const int to = T[s][i];
            if (to == prev) { continue; }
            if (i > 0 and empty) { self(self, to, s, true, init); }
            const auto Y = self(self, to, s, i == 0 and empty, Xs);
            const int c = C[s][to];
            for (int w = 0; w <= W - c; w++) { chmax(Xs[w + c], Y[w]); }
        }
        for (int w = 0; w <= W; w++) {
            Xs[w] += P[s];
            if (empty) { chmax(ans, Xs[w]); }
        }
        return Xs;
    };
    RecDP(RecDP, 0, -1, true, init);
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 62544