#include <bits/stdc++.h>
using namespace std;
const int N = 206;
vector<int> E[N];
int dp[N][N], c[N];
int n, k;
void dfs(int node, int p) {
  for (auto it : E[node]) {
    if (it != p) {
      dfs(it, node);
    }
  }
  for (int d = 0; d <= N - 1; d += 1) {
    if (d == 0) {
      dp[node][d] = c[node];
      for (auto it : E[node]) {
        if (it != p) {
          dp[node][d] += dp[it][max(0, k - d - 1)];
        }
      }
    }
    if (d > 0) {
      for (auto it : E[node]) {
        if (it != p) {
          int cur = dp[it][d - 1];
          for (auto itt : E[node]) {
            if (itt != it && itt != p) {
              cur += dp[itt][max(d - 1, k - d - 1)];
            }
          }
          dp[node][d] = max(dp[node][d], cur);
        }
      }
    }
  }
  for (int i = N - 2; i >= 0; i--) {
    dp[node][i] = max(dp[node][i], dp[node][i + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  k += 1;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  dfs(1, 0);
  cout << dp[1][0] << '\n';
  return 0;
}
