#include <bits/stdc++.h>
int n, m, Fa[200005], Siz[200005];
struct Edge {
  int x, y, z;
} e[200005];
inline bool operator<(const Edge& a, const Edge& b) { return a.z < b.z; }
struct Query {
  int q, ID;
} q[200005];
inline bool operator<(const Query& a, const Query& b) { return a.q < b.q; }
long long Ans[200005], Cur;
int Get(const int x) { return x == Fa[x] ? x : Fa[x] = Get(Fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
  for (int i = 1; i <= n; ++i) Siz[Fa[i] = i] = 1;
  for (int i = 1; i <= m; ++i) scanf("%d", &q[i].q), q[i].ID = i;
  std::sort(e + 1, e + n), std::sort(q + 1, q + m + 1);
  int Ae = 1;
  for (int i = 1; i <= m; ++i) {
    while (Ae < n && e[Ae].z <= q[i].q) {
      int x = e[Ae].x, y = e[Ae].y;
      ++Ae, x = Get(x), y = Get(y);
      if (x == y) continue;
      Cur -= Siz[x] * (Siz[x] - 1ll) >> 1;
      Cur -= Siz[y] * (Siz[y] - 1ll) >> 1;
      Siz[x] += Siz[y], Fa[y] = x;
      Cur += Siz[x] * (Siz[x] - 1ll) >> 1;
    }
    Ans[q[i].ID] = Cur;
  }
  for (int i = 1; i <= m; ++i) printf("%I64d%c", Ans[i], i == m ? '\n' : ' ');
  return 0;
}
