#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int N = 2e2 + 10;
int n, k;
int a[N], d[N], dp[N][N];
vector<int> g[N];
void dfs(int u, int fa) {
  dp[u][0] = a[u];
  for (int x : g[u]) {
    if (x == fa) continue;
    dfs(x, u);
    d[u] = max(d[u], d[x] + 1);
    dp[u][0] += dp[x][k];
  }
  for (int i = 1; i <= n; i++) {
    for (int x : g[u])
      if (x != fa) {
        int tmp = dp[x][i - 1];
        for (int y : g[u])
          if (y != fa && y != x) {
            tmp += dp[y][max(i - 1, k - i)];
          }
        dp[u][i] = max(dp[u][i], tmp);
      }
  }
  for (int i = n; i >= 0; i--) dp[u][i] = max(dp[u][i], dp[u][i + 1]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  printf("%d\n", dp[1][0]);
  return 0;
}
