#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define print(k) cout<<#k"="<<k<<endl;
#define LL long long
using namespace std;
struct Son
{
LL n,next;
}son[110];
struct Node
{
LL v,p,head;
}node[110];
LL ans[110][110],n,k,root;
void dfs(LL n)
{
LL i,j,t,s=node[n].head;
ans[n][1]=node[n].v;
while(s>=0)
{
dfs(son[s].n);
for(j=k;j>1;j--)
{
for(t=1;t<j;t++)
{
ans[n][j]=max(ans[n][j],ans[n][j-t]+ans[son[s].n][t]);
}
}
s=son[s].next;
}
}
int main()
{
LL j,i,a,b;
ios::sync_with_stdio(false);
while(cin>>n>>k)
{
for(i=0;i<n;i++)
{
cin>>node[i].v;
son[i].next=-1;
node[i].p=-1;
node[i].head=-1;
}
int sn=0;
for(i=0;i<n-1;i++)
{
cin>>a>>b;
if(node[b].p>=0) swap(a,b);
son[sn].n=b;
son[sn].next=node[a].head;
node[a].head=sn++;
node[b].p=a;
}
root=0;
while(node[root].p>=0) root=node[root].p;
memset(ans,0,sizeof(ans));
dfs(root);
LL answer=0;
for(i=0;i<n;i++) answer=max(answer,ans[i][k]);
cout<<answer<<endl;
}
return 0;
}