#include <bits/stdc++.h>
using namespace std;
const int mxn = 2e5 + 100;
int parent[mxn], sz[mxn];
long long ans[mxn], ret = 0;
array<int, 3> edges[mxn];
array<int, 2> queries[mxn];
int find(int p) {
  if (p == parent[p]) return p;
  return parent[p] = find(parent[p]);
}
long long nC2(int n) { return (1LL * n * (n - 1)) / 2; }
void merge(int u, int v) {
  int pu = find(u), pv = find(v);
  if (pu == pv) return;
  if (sz[pu] < sz[pv]) swap(pu, pv);
  ret += nC2(sz[pu] + sz[pv]) - nC2(sz[pu]) - nC2(sz[pv]);
  sz[pu] += sz[pv], parent[pv] = pu;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) parent[i] = i, sz[i] = 1;
  for (int i = 0; i < n - 1; i++)
    scanf("%d%d%d", &edges[i][1], &edges[i][2], &edges[i][0]);
  for (int i = 0; i < m; i++) scanf("%d", &queries[i][0]), queries[i][1] = i;
  sort(edges, edges + n - 1);
  sort(queries, queries + m);
  for (int j = 0, i = 0; j < m; ++j) {
    while (i < n - 1 && edges[i][0] <= queries[j][0])
      merge(edges[i][1], edges[i][2]), ++i;
    ans[queries[j][1]] = ret;
  }
  for (int i = 0; i < m; i++) printf("%lld ", ans[i]);
}
