#include <bits/stdc++.h>
using namespace std;
int n, k, a[205], tot, head[205], q[205], num;
bool vis[205];
struct node {
  int v, next;
} e[205 << 1];
void dfs(int x, int pre, int dp) {
  if (dp > k) return;
  a[x] -= num;
  for (int i = head[x]; i != -1; i = e[i].next) {
    int v = e[i].v;
    if (v == pre) continue;
    dfs(v, x, dp + 1);
  }
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d %d", &x, &y);
    e[tot] = node{y, head[x]}, head[x] = tot++;
    e[tot] = node{x, head[y]}, head[y] = tot++;
  }
  int l = 0, r = 1;
  q[++l] = 1, vis[1] = true;
  while (l <= r) {
    int x = q[l++];
    for (int i = head[x]; i != -1; i = e[i].next) {
      int v = e[i].v;
      if (!vis[v]) q[++r] = v, vis[v] = true;
    }
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    if (a[q[i]] <= 0) continue;
    num = a[q[i]];
    ans += num;
    dfs(q[i], 0, 0);
  }
  printf("%d\n", ans);
  return 0;
}
