#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int Mod = 1e9 + 7;
const int INF = 2e9 + 7;
void in() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
struct haha {
  int u, v, w;
  bool operator<(const haha& x) const { return w < x.w; }
};
int par[N];
struct DSU {
  void init(int n) {
    for (int i = 1; i <= n; i++) par[i] = -1;
  }
  int root(int u) { return par[u] < 0 ? u : par[u] = root(par[u]); }
  void join(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return;
    if (par[u] > par[v]) swap(u, v);
    par[u] += par[v];
    par[v] = u;
  }
} dsu;
haha a[N];
int query[N];
int pos[N];
long long f[N];
int main() {
  in();
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    cin >> a[i].u >> a[i].v >> a[i].w;
  }
  for (int i = 1; i <= q; i++) {
    cin >> query[i];
    pos[i] = query[i];
  }
  sort(a + 1, a + n);
  sort(query + 1, query + 1 + q);
  dsu.init(n);
  int j = 1;
  long long res = 0;
  for (int i = 1; i <= q; i++) {
    while (j < n && a[j].w <= query[i]) {
      array<long long, 2> _size = {-par[dsu.root(a[j].u)],
                                   -par[dsu.root(a[j].v)]};
      res -= _size[1] * (_size[1] - 1) / 2 + _size[0] * (_size[0] - 1) / 2;
      dsu.join(a[j].u, a[j].v);
      int size = -par[dsu.root(a[j].u)];
      res += 1LL * size * (size - 1) / 2;
      j++;
    }
    f[query[i]] = res;
  }
  for (int i = 1; i <= q; i++) cout << f[pos[i]] << " ";
  return 0;
}
