#include <bits/stdc++.h>
using namespace std;
const long long maxn = 250, maxv = 100, mod = 1e9 + 7, maxa = 1005, maxs = 820,
                maxb = 20, base = 737, base2 = 3079, mod3 = 998244353,
                delt = 10513;
const long long inf = 2e16;
const long long infint = 1e9 + 11;
long long max(long long x, long long y) { return (x > y ? x : y); }
long long min(long long x, long long y) { return (x < y ? x : y); }
long long w[maxn];
vector<long long> v[maxn];
long long dp[maxn][maxn];
long long n, k;
long long tmp[maxn];
void dfs(long long x, long long par) {
  for (auto u : v[x]) {
    if (u == par) {
      continue;
    }
    dfs(u, x);
  }
  for (long long i = 0; i <= k; i++) {
    tmp[i] = 0;
    for (auto u : v[x]) {
      if (u != par) {
        tmp[i] += dp[u][i];
      }
    }
  }
  dp[x][0] = tmp[k] + w[x];
  for (long long i = k; i >= 1; i--) {
    for (auto u : v[x]) {
      if (u == par) {
        continue;
      }
      long long ind = max(k - i, i - 1);
      dp[x][i] = max(dp[x][i], dp[u][i - 1] + tmp[ind] - dp[u][ind]);
    }
    dp[x][i] = max(dp[x][i], dp[x][i + 1]);
  }
  dp[x][0] = max(dp[x][1], dp[x][0]);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> w[i];
    dp[i][0] = w[i];
  }
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(0, -1);
  long long ans = 0;
  for (long long i = 0; i <= k; i++) {
    ans = max(ans, dp[0][i]);
  }
  cout << ans << endl;
  return 0;
}
