#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i)) #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n' #define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair Pii; typedef vector vint; typedef vector vll; const ll INF = INT_MAX; const ll MOD = 1e9+7; struct Edge{ int src,dst; ll weight; Edge(int a,int b,ll c):src(a),dst(b),weight(c){} }; int N,M; ll U[210]; vector > G; ll dp[210][2100]; void dfs(int v,int par){ repeat(i,M+1){ dp[v][i]=U[v]; } for(Edge e:G[v])if(e.dst!=par){ dfs(e.dst,v); for(int m=M;m>=0;m--){ repeat(i,m-2*e.weight+1){ dp[v][m]=max(dp[v][m],dp[v][m-i-2*e.weight]+dp[e.dst][i]); } } } //debug(v); //debugArray(dp[v],M+1); } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; G.resize(N); repeat(i,N){ cin >> U[i]; } //debugArray(U,N); repeat(i,N-1){ int a,b;ll c; cin >> a >> b >> c; G[a].push_back({a,b,c}); G[b].push_back({b,a,c}); } dfs(0,-1); cout << dp[0][M] << endl; return 0; }