#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
ll n , k;
vector<ll> arr;
ll dfs(vector<ll> graph[] , ll source , ll par , ll k){
if(k == 0) return 0;
ll ans = arr[source];
for(auto child : graph[source]){
if(child == par) continue;
if(k) ans = max(ans , dfs(graph , child , source , k - 1) + arr[source]);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
arr.resize(n + 1);
for(ll i = 1 ; i <= n ; i++){
cin >> arr[i];
}
vector<ll> graph[n + 1];
for(ll i = 1 ; i < n ; i++){
ll x , y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
ll ans = 0;
for(ll i = 1 ; i <= n ; i++){
ans = max(ans, dfs(graph , i , -1 , k));
}
cout << ans << "\n";
return 0;
}
// Author : Raj (raj_singh35)