#include <bits/stdc++.h>
using namespace std;
const int N = 201;
int n, k;
int w[N];
vector<int> g[N];
int dp[N][N];
int cur[N];
void dfs(int v, int last = -1) {
  for (int u : g[v]) {
    if (u != last) {
      dfs(u, v);
    }
  }
  fill(cur, cur + N, 0);
  for (int u : g[v]) {
    if (u != last) {
      for (int h = 0; h <= k; ++h) {
        cur[h] += dp[u][h];
      }
    }
  }
  for (int d = 0; d <= k; ++d) {
    for (int m = max(0, d - 1); m < k && max(k - 1 - m, d - 1) >= m; ++m) {
      for (int u : g[v]) {
        if (u != last) {
          dp[v][d] = max(dp[v][d], cur[max(k - 1 - m, d - 1)] -
                                       dp[u][max(k - 1 - m, d - 1)] + dp[u][m]);
        }
      }
    }
  }
  int a = w[v];
  for (int u : g[v]) {
    if (u != last) {
      a += dp[u][k];
    }
  }
  dp[v][0] = max(dp[v][0], a);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int v = 0; v < n; ++v) {
    cin >> w[v];
  }
  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0);
  cout << dp[0][0] << '\n';
  return 0;
}
