#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int val[N];
int dp[N][N];
vector<int> v[N];
int n, k;
void solve(int node, int par) {
  dp[node][0] = val[node];
  for (auto to : v[node]) {
    if (to != par) solve(to, node);
  }
  for (int dep = 0; dep < N; ++dep) {
    if (dep == 0) {
      for (auto to : v[node]) {
        if (to == par) continue;
        dp[node][dep] += dp[to][max(0, k - dep - 1)];
      }
    } else {
      for (auto to : v[node]) {
        if (to == par) continue;
        int cur = dp[to][dep - 1];
        for (auto other : v[node]) {
          if (other == par || other == to) continue;
          cur += dp[other][max(dep - 1, k - dep - 1)];
        }
        dp[node][dep] = max(dp[node][dep], cur);
      }
    }
  }
  for (int dep = N - 1; dep > 0; --dep) {
    dp[node][dep - 1] = max(dp[node][dep - 1], dp[node][dep]);
  }
}
int main() {
  cin >> n >> k;
  k++;
  for (int i = 1; i <= n; i++) cin >> val[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  solve(1, 1);
  cout << dp[1][0];
  return 0;
}
