#include <bits/stdc++.h>
using namespace std;
int64_t n, k;
vector<vector<int64_t>> dp;
vector<int64_t> w;
vector<vector<int64_t>> tree;
void calc(int64_t t, int64_t p = -1) {
  if (p != -1 && tree[t].size() == 1) {
    dp[t][0] = w[t];
    return;
  }
  for (int64_t i = 0; i < tree[t].size(); ++i) {
    int64_t e = tree[t][i];
    if (e == p) {
      continue;
    }
    calc(e, t);
  }
  dp[t][0] = w[t];
  for (int64_t i = 0; i < tree[t].size(); ++i) {
    int64_t e = tree[t][i];
    if (e == p) {
      continue;
    }
    dp[t][0] += dp[e][k - 1];
  }
  for (int64_t dep = 1; dep < k; ++dep) {
    for (int64_t i = 0; i < tree[t].size(); ++i) {
      int64_t e = tree[t][i];
      if (e == p) {
        continue;
      }
      int64_t sum = dp[e][dep - 1];
      for (int64_t j = 0; j < tree[t].size(); ++j) {
        int64_t f = tree[t][j];
        if (f == e || f == p) {
          continue;
        }
        sum += dp[f][max(dep - 1, k - dep - 1)];
      }
      dp[t][dep] = max(dp[t][dep], sum);
    }
  }
  for (int64_t dep = k - 1; dep > 0; --dep) {
    dp[t][dep - 1] = max(dp[t][dep - 1], dp[t][dep]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  ++k;
  dp.assign(n, vector<int64_t>(k));
  w.resize(n);
  tree.resize(n);
  for (int64_t i = 0; i < n; ++i) {
    cin >> w[i];
  }
  for (int64_t i = 0; i < n - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    --a;
    --b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  calc(0);
  cout << dp[0][0];
}
