#include <bits/stdc++.h>
using namespace std;
const int maxn = 203;
int dp[maxn][maxn], a[maxn];
int k;
vector<int> adj[maxn];
void dfs(int v, int p = -1) {
  dp[v][0] = a[v];
  int sigdp[maxn], ch = 0;
  ;
  fill(sigdp, sigdp + maxn, 0);
  for (auto u : adj[v]) {
    if (u == p) continue;
    dfs(u, v);
    dp[v][0] += dp[u][k];
    for (int i = 0; i < maxn; i++) {
      sigdp[i] += dp[u][i];
    }
    ch++;
  }
  for (auto u : adj[v]) {
    if (u == p) continue;
    for (int i = 1; i < maxn; i++) {
      for (int j = i; j < maxn; j++) {
        dp[v][i] =
            max(dp[v][i], dp[u][j - 1] + sigdp[max(j - 1, max(k - j, i - 1))] -
                              dp[u][max(j - 1, max(k - j, i - 1))]);
      }
    }
  }
  for (int i = maxn - 2; i >= 0; i--) dp[v][i] = max(dp[v][i], dp[v][i + 1]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  dfs(0);
  cout << *max_element(dp[0], dp[0] + k + 2);
}
