#include <bits/stdc++.h>
using namespace std;
long long par[200110];
long long s[200110];
long long form(long long a) { return (a * (a - 1)) / 2; }
long long parent(long long a) {
  if (par[a] == a) {
    return a;
  }
  par[a] = parent(par[a]);
  return par[a];
}
void uni(long long a, long long b, long long& ans) {
  a = parent(a);
  b = parent(b);
  if (a == b) return;
  if (s[a] < s[b]) {
    swap(a, b);
  }
  ans -= (form(s[a]) + form(s[b]));
  s[a] += s[b];
  ans += form(s[a]);
  par[b] = a;
}
bool custom(pair<pair<long long, long long>, long long> p1,
            pair<pair<long long, long long>, long long> p2) {
  return p1.second < p2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  long long n, m;
  cin >> n >> m;
  pair<pair<long long, long long>, long long> p[n];
  for (long long i = 0; i < n - 1; i++) {
    cin >> p[i].first.first >> p[i].first.second >> p[i].second;
  }
  sort(p, p + (n - 1), custom);
  for (long long i = 1; i <= n + 10; i++) {
    par[i] = i;
    s[i] = 1;
  }
  long long q[m];
  long long val = 0;
  for (long long i = 0; i < m; i++) {
    cin >> q[i];
    val = max(val, q[i]);
  }
  long long g[200110] = {};
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    uni(p[i].first.first, p[i].first.second, ans);
    g[p[i].second] = ans;
  }
  long long r = g[0];
  for (long long i = 0; i <= val + 1; i++) {
    if (g[i] == 0) {
      g[i] = r;
    } else {
      r = g[i];
    }
  }
  for (long long i = 0; i < m; i++) {
    cout << g[q[i]] << " ";
  }
}
