#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k;
int ans = 0;
int dp[205][205], a[205], temp[205][205];
vector<int> node[205];
void dfs(int u, int p) {
  dp[u][0] = a[u];
  for (int i = 0; i <= k; i++) temp[u][i] = 0;
  for (auto j : node[u]) {
    if (j == p) continue;
    dfs(j, u);
    dp[u][0] = max(dp[u][0], a[u] + dp[j][k - 1]);
    temp[u][0] += dp[j][k - 1];
    dp[u][0] = max(dp[u][0], dp[j][0]);
    for (int i = 1; i < k; i++) {
      dp[u][i] = max(dp[u][i], dp[j][i - 1]);
      dp[u][i] = max(dp[u][i], dp[j][i]);
      temp[u][i] += dp[j][i - 1];
    }
  }
  dp[u][0] = max(dp[u][0], temp[u][0] + a[u]);
  for (int j : node[u]) {
    if (j == p) continue;
    for (int i = 1; i < k; i++) {
      if ((i * 2) >= k) {
        dp[u][k - i] =
            max(temp[u][i] + dp[j][k - i - 1] - dp[j][i - 1], dp[u][k - i]);
        dp[u][i] = max(dp[u][i], temp[u][i]);
      }
    }
  }
  for (int i = k; i >= 1; i--) dp[u][i - 1] = max(dp[u][i - 1], dp[u][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  if (fopen("GUARDS.INP", "r")) {
    freopen("GUARDS.INP", "r", stdin);
    freopen("GUARDS.OUT", "w", stdout);
  }
  cin >> n >> k;
  k++;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    node[u].push_back(v);
    node[v].push_back(u);
  }
  dfs(1, 1);
  for (int j = 1; j <= n; j++)
    for (int i = 0; i < k; i++) ans = max(ans, dp[j][i]);
  cout << ans;
}
