#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 222;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long n, k;
vector<long long> adj[N];
long long dp[N][N], dp2[N][N], a[N];
void input() {
  cin >> n >> k;
  k++;
  for (long long i = (1); i <= (n); i++) cin >> a[i];
  for (long long i = (1); i <= (n - 1); i++) {
    long long x, y;
    cin >> x >> y;
    ;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
}
void dfs(long long cur = 1, long long prev = 0) {
  for (long long i : adj[cur])
    if (i != prev) dfs(i, cur);
  for (long long p = (k); p >= (0); p--) {
    if (p >= (k + 1) / 2) {
      long long mx = -inf;
      for (long long i : adj[cur])
        if (i != prev) {
          dp2[cur][p] += dp2[i][p - 1];
          mx = max(mx, dp[i][p - 1] - dp2[i][p - 1]);
        }
      dp[cur][p] = dp2[cur][p] + mx;
    } else {
      long long mx = -inf;
      if (!p) mx = a[cur];
      for (long long i : adj[cur])
        if (i != prev) {
          dp[cur][p] += dp2[i][(k - p) - 1];
          if (p) mx = max(mx, dp[i][p - 1] - dp2[i][(k - p) - 1]);
        }
      dp[cur][p] += mx;
      dp2[cur][p] = max(dp[cur][p], dp2[cur][p + 1]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  input();
  dfs();
  cout << dp2[1][0];
}
