#include <bits/stdc++.h>
using namespace std;
int f[2000000];
long long sum[2000000];
long long ans[2000000];
long long temp = 0;
struct tr {
  int u;
  int v;
  int w;
};
tr t[2000000];
struct tr2 {
  int l;
  int r;
};
tr2 t2[2000000];
bool cmp(tr x, tr y) { return x.w < y.w; }
bool cmp1(tr2 x, tr2 y) { return x.l < y.l; }
int find(int x) {
  if (f[x] != x) f[x] = find(f[x]);
  return f[x];
}
void nion(int a, int b) {
  int x, y;
  x = find(a);
  y = find(b);
  if (x != y) {
    temp = temp - (sum[x] * (sum[x] - 1) / 2);
    temp = temp - (sum[y] * (sum[y] - 1) / 2);
    f[x] = y;
    sum[y] = sum[x] + sum[y];
    temp = temp + (sum[y] * (sum[y] - 1) / 2);
  }
}
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  int i = 1;
  while (i < n) {
    scanf("%d%d%d", &t[i].u, &t[i].v, &t[i].w);
    i++;
  }
  i = 0;
  while (i < m) {
    scanf("%d", &t2[i].l);
    t2[i].r = i;
    i++;
  }
  i = 0;
  while (i <= n) {
    f[i] = i;
    sum[i] = 1;
    i++;
  }
  sort(t + 1, t + n, cmp);
  sort(t2, t2 + m, cmp1);
  int len = 1;
  for (i = 0; i < m; i++) {
    while (t2[i].l >= t[len].w && len < n) {
      nion(t[len].u, t[len].v);
      len++;
    }
    ans[t2[i].r] = temp;
  }
  i = 0;
  while (i < m) {
    printf("%lld ", ans[i]);
    i++;
  }
  printf("\n");
  return 0;
}
