#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair<ll, ll>;
using vec = vector<ll>;
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
ll parent[200009], sizes[200009];
void make_set(int v) {
  parent[v] = v;
  sizes[v] = 1;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
ll re = 0;
ll cnt(ll a) { return 1ll * a * (a - 1) / 2; }
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sizes[a] < sizes[b]) swap(a, b);
    re -= cnt(sizes[a]);
    re -= cnt(sizes[b]);
    parent[b] = a;
    sizes[a] += sizes[b];
    re += cnt(sizes[a]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;
  vector<array<int, 3>> inputs(n - 1);
  for (ll i = 0; i < n - 1; i++) {
    cin >> inputs[i][1] >> inputs[i][2] >> inputs[i][0];
    inputs[i][1]--;
    inputs[i][2]--;
  }
  vector<pa> weights(m);
  vec answer(m);
  for (ll i = 0; i < m; i++) {
    cin >> weights[i].first;
    weights[i].second = i;
  }
  for (ll i = 0; i < n + 1; i++) {
    make_set(i);
  }
  sort(inputs.begin(), inputs.end());
  sort(weights.begin(), weights.end());
  ll pos = 0;
  for (ll i = 0; i < m; i++) {
    while (pos < n - 1 && inputs[pos][0] <= weights[i].first) {
      union_sets(inputs[pos][1], inputs[pos][2]);
      ++pos;
    }
    answer[weights[i].second] = re;
  }
  for (int i = 0; i < m; ++i) {
    cout << answer[i] << " ";
  }
  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
  return 0;
}
