#include using namespace std; using pii = pair; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) #define all(v) v.begin(),v.end() #define debug(x) cerr << #x << " : " << x << endl template bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } template bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; } // vector template istream& operator >> (istream &is , vector &v) { for(T &a : v) is >> a; return is; } template ostream& operator << (ostream &os , const vector &v) { for(const T &t : v) os << "\t" << t; return os << endl; } // pair template ostream& operator << (ostream &os , const pair &v) { return os << "<" << v.first << ", " << v.second << ">"; } const int INF = 1 << 30; const ll INFL = 1LL << 60; class Solver { public: int N, M; vector U; vector> E; vector> memo; void rec(int now, int pre) { // cerr << "@" << now << " from " << pre << endl; memo[now][0] = U[now]; for(auto e: E[now]) { if(e.first == pre) continue; rec(e.first, now); map mp; for(auto np : memo[now]) { for(auto p : memo[e.first]) { int m = p.first + np.first + e.second * 2; if(m <= M) set_max(mp[m], p.second + np.second); } } for(auto p : mp) { set_max(memo[now][p.first], p.second); } } } bool solve() { cin >> N >> M; U.resize(N); cin >> U; E.resize(N); rep(i, N - 1) { int a, b, c; cin >> a >> b >> c; E[a].push_back(make_pair(b, c)); E[b].push_back(make_pair(a, c)); } memo.resize(N); rec(0, -1); int ans = 0; for(auto p : memo[0]) { set_max(ans, p.second); } cout << ans << endl; return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }