#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 201;
int dp[N][N], c[N], n, k;
vector<int> a[N];
void Solve() {
  function<void(int, int)> dfs = [&](int p, int u) {
    dp[u][0] = c[u];
    for (int v : a[u]) {
      if (v == p) continue;
      dfs(u, v);
    }
    for (int dep = 0; dep <= n; dep++) {
      if (dep == 0) {
        for (int &x : a[u]) {
          if (x != p) dp[u][dep] += dp[x][k - 1];
        }
      } else {
        for (int &x : a[u]) {
          if (x == p) continue;
          int s = dp[x][dep - 1];
          for (int &y : a[u]) {
            if (y == x || y == p) continue;
            s += dp[y][max(dep - 1, k - dep - 1)];
          }
          dp[u][dep] = max(dp[u][dep], s);
        }
      }
    }
    for (int i = n - 1; i > -1; i--) dp[u][i] = max(dp[u][i], dp[u][i + 1]);
  };
  k++;
  dfs(0, 1);
  cout << dp[1][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  Solve();
  return 0;
}
