#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 200;
int a[N], dep[N];
vector<int> adj[N], ch[N];
int best[N][N];
void dfs(int u, int p, int d) {
  dep[u] = d;
  for (int v : adj[u]) {
    if (v != p) {
      dfs(v, u, d + 1);
      ch[u].push_back(v);
    }
  }
}
int n, k;
int solve(int u, int d) {
  if (d >= n) return 0;
  if (best[u][d] != -1) return best[u][d];
  int& res = best[u][d];
  if (ch[u].empty()) {
    res = d == 0 ? a[u] : 0;
  } else if (d == 0) {
    res = a[u] + solve(u, k + 1);
  } else if (2 * d > k) {
    res = 0;
    for (int v : ch[u]) {
      int curr = 0;
      for (int dd = d - 1; dd < n; dd++) {
        curr = max(curr, solve(v, dd));
      }
      res += curr;
    }
  } else {
    res = 0;
    int extra = 0;
    for (int v : ch[u]) {
      int curr = 0;
      for (int dd = k - d; dd < n; dd++) {
        curr = max(curr, solve(v, dd));
      }
      res += curr;
      int ce = 0;
      for (int dd = d - 1; dd < k - d; dd++) {
        ce = max(ce, solve(v, dd));
      }
      extra = max(extra, ce - curr);
    }
    res += extra;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, 0, 0);
  memset(best, -1, sizeof best);
  int ans = 0;
  for (int u = 0; u < n; u++) {
    for (int d = 0; d < n; d++) {
      ans = max(ans, solve(u, d));
    }
  }
  cout << ans << endl;
  return 0;
}
