#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5;
int N, Q, par[MN];
ll sz[MN];
struct Edge {
  int u, v, w;
  bool operator<(const Edge &o) const { return w < o.w; }
};
ll cur, ans[MN];
int find(int u) { return u == par[u] ? u : par[u] = find(par[u]); }
void merge(int u, int v) {
  u = find(u), v = find(v);
  if (u == v) return;
  cur += sz[u] * sz[v];
  sz[u] += sz[v];
  par[v] = u;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) par[i] = i, sz[i] = 1;
  vector<Edge> es;
  vector<pii> qs;
  for (int i = 1; i < N; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    es.push_back({u, v, w});
  }
  sort(es.begin(), es.end());
  for (int i = 0; i < Q; i++) {
    int q;
    cin >> q;
    qs.emplace_back(q, i);
  }
  sort(qs.begin(), qs.end());
  int pos = 0;
  for (int i = 0; i < Q; i++) {
    auto [q, idx] = qs[i];
    while (pos < es.size() && es[pos].w <= q) {
      merge(es[pos].u, es[pos].v);
      pos++;
    }
    ans[idx] = cur;
  }
  for (int i = 0; i < Q; i++) cout << ans[i] << " ";
  return 0;
}
