#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
namespace FastIO {
inline int read() {
  int x = 0, F = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') F = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
  return x * F;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = ~x + 1;
  if (x > 9) write(x / 10);
  putchar((x % 10) | 48);
}
inline void write(int x, char ch) { write(x), putchar(ch); }
}  // namespace FastIO
using namespace FastIO;
int n, k, a[N], f[N][N];
struct Graph {
  int tot, to[N], nxt[N], head[N];
  inline void connect(int u, int v) {
    to[++tot] = v;
    nxt[tot] = head[u], head[u] = tot;
  }
} G;
void Dfs(int u, int fa) {
  for (int i = G.head[u]; i; i = G.nxt[i]) {
    int v = G.to[i];
    if (v == fa) continue;
    Dfs(v, u);
  }
  f[u][0] = a[u];
  for (int j = G.head[u]; j; j = G.nxt[j]) {
    int v = G.to[j];
    if (v == fa) continue;
    f[u][0] += f[v][k - 1];
  }
  for (int i = 1; i <= n; i++) {
    int sum = 0, res = 0;
    for (int j = G.head[u]; j; j = G.nxt[j]) {
      int v = G.to[j];
      if (v == fa) continue;
      sum += f[v][max(i - 1, k - i - 1)];
    }
    for (int j = G.head[u]; j; j = G.nxt[j]) {
      int v = G.to[j];
      if (v == fa) continue;
      res = max(res, sum + f[v][i - 1] - f[v][max(i - 1, k - i - 1)]);
    }
    f[u][i] = res;
  }
  for (int i = n - 1; i >= 0; i--) f[u][i] = max(f[u][i], f[u][i + 1]);
}
int main() {
  cin >> n >> k, k++;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G.connect(u, v), G.connect(v, u);
  }
  Dfs(1, 0);
  cout << f[1][0] << endl;
  return 0;
}
