#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
const int MAXN = 110;
vector<int>a[MAXN];
int n,m,v[MAXN],vis[MAXN],dp[MAXN][MAXN];
void dfs(int root)
{
dp[root][1] = v[root];
vis[root] = 1;
int i, len = a[root].size(), j, k;
int cnt = 0;
for(i=0; i<len; i++){
int t = a[root][i];
if(!vis[t]){
dfs(t);
for(j=m; j>0; j--){
for(k=1; k<j; k++){
dp[root][j] = max(dp[root][j], dp[root][j-k]+dp[t][k]);
}
}
}
}
}
int main()
{
int i,j;
while(cin>>n>>m)
{
for(i=0; i<n; i++){
scanf("%d",&v[i]);
a[i].clear();
}
for(i=1; i<n; i++){
int x,y;
scanf("%d%d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
memset(vis,0,sizeof(vis));
memset(dp,0,sizeof(dp));
dfs(0);
int ans = 0;
for(i=0; i<n; i++){
ans = max(ans, dp[i][m]);
}
cout<<ans<<endl;
}
}