#include <bits/stdc++.h>
using namespace std;
int n, m, op, id[2005], tp[2005], inq[2005];
double a[2005][2005];
long long dist[2005];
void pivot(int r, int c) {
  swap(id[r + n], id[c]);
  double tmp = -a[r][c];
  a[r][c] = -1;
  for (int i = 0; i <= n; i++) a[r][i] /= tmp;
  for (int i = 0; i <= m; i++)
    if (a[i][c] && i != r) {
      tmp = a[i][c];
      a[i][c] = 0;
      for (int j = 0; j <= n; j++) a[i][j] += tmp * a[r][j];
    }
}
double simplex(int M) {
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) a[i][j] *= -1;
  while (1) {
    int i = 0, j = 0;
    double tmp = -1e-5;
    for (int k = 1; k <= m; k++)
      if (a[k][0] < tmp) tmp = a[i = k][0];
    if (!i) break;
    for (int k = 1; k <= n; k++)
      if (a[i][k] > 1e-5) {
        j = k;
        break;
      }
    if (!j) return M + 1;
    pivot(i, j);
  }
  while (1) {
    int i = 0, j = 0;
    double tmp = 1e-5;
    for (int k = 1; k <= n; k++)
      if (a[0][k] > tmp) tmp = a[0][j = k];
    if (!j) break;
    tmp = 1e9;
    for (int k = 1; k <= m; k++)
      if (a[k][j] < -1e-5 && -a[k][0] / a[k][j] < tmp)
        i = k, tmp = -a[k][0] / a[k][j];
    pivot(i, j);
  }
  return a[0][0];
}
struct node {
  int v, w;
  node *nxt;
} edge[2005 * 2], *head[2005], *ncnt;
void addedge(int u, int v, int w) {
  ncnt++;
  ncnt->v = v, ncnt->w = w, ncnt->nxt = head[u];
  head[u] = ncnt;
}
void spfa(int s) {
  queue<int> q;
  memset(dist, 0x3f, sizeof(dist));
  dist[s] = 0, inq[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (node *p = head[u]; p; p = p->nxt) {
      int v = p->v, w = p->w;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        if (!inq[v]) {
          inq[v] = 1;
          q.push(v);
        }
      }
    }
  }
}
int main() {
  int N, M = 0, K;
  scanf("%d%d", &N, &K);
  ncnt = &edge[0];
  n = N, m = 2 * N + 2;
  for (int i = 1; i <= N; i++) {
    scanf("%lf", &a[0][i]);
    M += a[0][i];
  }
  for (int i = 1; i < N; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    addedge(v, u, w);
  }
  for (int i = 1; i <= N; i++) {
    a[i][0] = -1;
    spfa(i);
    for (int j = 1; j <= N; j++)
      if (dist[j] <= K) a[i][j] = -1;
  }
  a[N + 1][0] = M, a[N + 2][0] = -M;
  for (int i = 1; i <= N; i++) {
    a[n + 1][i] = 1, a[n + 2][i] = -1;
    a[n + 2 + i][0] = 1, a[n + 2 + i][i] = 1;
  }
  printf("%.0f\n", M - simplex(M));
}
