#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000000000;
long long mod = 1000000000;
long double pi = 3.141592653589793238;
void pls() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long N = 2e2 + 5;
long long n, k;
vector<long long> val;
vector<long long> g[N];
long long dp[N][N];
void dfs(int ix = 0, int p = -1) {
  dp[ix][0] = val[ix];
  for (auto x : g[ix]) {
    if (x == p) continue;
    dfs(x, ix);
    dp[ix][0] += dp[x][k - 1];
  }
  for (int j = 0; j < k; j++) {
    for (auto x : g[ix]) {
      if (x == p) continue;
      long long sum = 0;
      sum += dp[x][j];
      int mn = j;
      int tak;
      for (auto y : g[ix]) {
        if (y == p || y == x) continue;
        tak = max(k - mn - 2, j * 1LL);
        sum += dp[y][tak];
        mn = min(tak, mn);
      }
      dp[ix][j + 1] = max(dp[ix][j + 1], sum);
    }
  }
  for (int j = k - 1; j >= 0; j--) dp[ix][j] = max(dp[ix][j], dp[ix][j + 1]);
}
void solve() {
  cin >> n >> k;
  k++;
  val.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> val[i];
  }
  for (int j = 0; j < n - 1; j++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs();
  cout << dp[0][0] << endl;
}
int main() {
  pls();
  solve();
  return 0;
}
