#include <bits/stdc++.h>
using namespace std;
const int mx = 200100;
struct node {
  int x, y, z;
} a[mx];
struct nod {
  int id, x;
} b[mx];
int fa[mx];
long long num[mx];
long long ans[mx];
int n, m;
bool cmp(node x, node y) { return x.z < y.z; }
bool cmp1(nod x, nod y) { return x.x < y.x; }
int find(int x) {
  if (x != fa[x]) {
    return fa[x] = find(fa[x]);
  }
  return fa[x];
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) fa[i] = i, num[i] = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i].x;
    b[i].id = i;
  }
  sort(a + 1, a + n, cmp);
  sort(b + 1, b + m + 1, cmp1);
  int l = 1;
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    while (l <= m && a[i].z > b[l].x) {
      ans[b[l].id] = sum;
      l++;
    }
    int x = find(a[i].x);
    int y = find(a[i].y);
    sum += num[y] * num[x];
    fa[x] = y;
    num[y] += num[x];
  }
  while (l <= m) {
    if (a[n - 1].z <= b[l].x) {
      ans[b[l].id] = sum;
    }
    l++;
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << " \n"[i == m];
  return 0;
}
