#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
int n, m, fa[M], siz[M];
long long int ans[M];
struct d1 {
  int x, y, z;
} a[M];
struct d2 {
  int q, id;
} b[M];
bool cmp1(d1 a, d1 b) { return a.z < b.z; }
bool cmp2(d2 a, d2 b) { return a.q < b.q; }
int fnd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fnd(fa[x]);
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n - 1; i++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
  for (int i = 1; i <= m; i++) scanf("%d", &b[i].q), b[i].id = i;
  sort(a + 1, a + n, cmp1);
  sort(b + 1, b + 1 + m, cmp2);
  for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  int pos = 1;
  long long int cur = 0;
  for (int i = 1; i <= m; i++) {
    while (a[pos].z <= b[i].q && pos <= n - 1) {
      int t1 = fnd(a[pos].x), t2 = fnd(a[pos].y);
      cur += 1LL * siz[t1] * siz[t2];
      if (t2 > t1) swap(t1, t2);
      siz[t1] += siz[t2];
      fa[t2] = t1;
      pos++;
    }
    ans[b[i].id] = cur;
  }
  for (int i = 1; i <= m; i++) printf("%lld ", ans[i]);
  return 0;
}
