#include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
long long read() {
  long long res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();
  return res * f;
}
struct node {
  int to, nt;
} e[maxn];
int cnt, head[maxn];
void add(int x, int y) {
  cnt++;
  e[cnt].nt = head[x];
  e[cnt].to = y;
  head[x] = cnt;
}
int n, k;
int a[maxn];
int f[maxn][maxn];
void dfs(int x, int fa) {
  f[x][0] = a[x];
  for (int i = head[x]; i; i = e[i].nt) {
    int to = e[i].to;
    if (to == fa) continue;
    dfs(to, x);
  }
  for (int j = 0; j < maxn; j++) {
    if (j == 0) {
      for (int i = head[x]; i; i = e[i].nt) {
        int to = e[i].to;
        if (to == fa) continue;
        f[x][j] += f[to][max(0, k - j - 1)];
      }
    } else {
      for (int i = head[x]; i; i = e[i].nt) {
        int to = e[i].to;
        if (to == fa) continue;
        int res = f[to][j - 1];
        for (int ii = head[x]; ii; ii = e[ii].nt) {
          int too = e[ii].to;
          if (too == fa || too == to) continue;
          res += f[too][max(j - 1, k - j - 1)];
        }
        f[x][j] = max(res, f[x][j]);
      }
    }
  }
  for (int j = maxn - 1; j > 0; j--) {
    f[x][j - 1] = max(f[x][j - 1], f[x][j]);
  }
}
int main() {
  n = read(), k = read() + 1;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  printf("%d\n", f[1][0]);
  return 0;
}
