#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long readll() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 2e5 + 5;
struct edge {
  int u, v, w;
} e[MAXN];
struct query {
  int x, id;
} q[MAXN];
bool cmpe(edge a, edge b) { return a.w < b.w; }
bool cmpq(query a, query b) { return a.x < b.x; }
int n, m, fa[MAXN];
long long sz[MAXN], t[MAXN], ans[MAXN];
int findFather(int x) {
  if (x == fa[x]) return x;
  return fa[x] = findFather(fa[x]);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i < n; ++i) e[i].u = read(), e[i].v = read(), e[i].w = read();
  for (int i = 1; i <= m; ++i) q[i].x = read(), q[i].id = i;
  sort(e + 1, e + n, cmpe);
  sort(q + 1, q + m + 1, cmpq);
  for (int i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
  int j = 1;
  long long res = 0;
  for (int i = 1; i <= m; ++i) {
    while (j < n && e[j].w <= q[i].x) {
      int u = findFather(e[j].u), v = findFather(e[j].v);
      if (u != v) {
        if (sz[u] > sz[v]) swap(u, v);
        res -= t[u] + t[v];
        fa[u] = v;
        sz[v] += sz[u];
        t[v] = sz[v] * (sz[v] - 1) / 2;
        res += t[v];
      }
      ++j;
    }
    ans[q[i].id] = res;
  }
  for (int i = 1; i <= m; ++i) printf("%lld ", ans[i]);
  puts("");
  return 0;
}
