#include <bits/stdc++.h>
using namespace std;
long long p[200005];
long long baap(long long x) {
  if (x == p[x]) return x;
  return p[x] = baap(p[x]);
}
long long calc(long long x) { return (x * (x - 1)) / 2; }
int main() {
  long long n, m, a, b, c;
  cin >> n >> m;
  vector<pair<long long, pair<long long, long long> > > v;
  long long wt[n + 2];
  for (int i = 0; i <= n; i++) {
    p[i] = i;
    wt[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b >> c;
    --a;
    --b;
    v.push_back({c, {a, b}});
  }
  vector<pair<long long, long long> > q;
  for (int i = 0; i < m; i++) {
    cin >> a;
    q.push_back({a, i});
  }
  long long ind = 0, vl = 0, ans[m + 1];
  sort(v.begin(), v.end());
  sort(q.begin(), q.end());
  for (int i = 0; i < m; i++) {
    while (ind < n - 1 && q[i].first >= v[ind].first) {
      long long x = v[ind].second.first;
      long long y = v[ind].second.second;
      x = baap(x);
      y = baap(y);
      if (wt[x] < wt[y]) swap(x, y);
      vl -= calc(wt[x]);
      vl -= calc(wt[y]);
      wt[x] += wt[y];
      vl += calc(wt[x]);
      p[y] = x;
      ind++;
    }
    ans[q[i].second] = vl;
  }
  for (int i = 0; i < m; i++) cout << ans[i] << " ";
  return 0;
}
