#include <bits/stdc++.h>
using namespace std;
struct Simplex {
  void pivot(int m, int n, double A[507 + 7][507 + 7], int *B, int *N, int r,
             int c) {
    int i, j;
    swap(N[c], B[r]);
    A[r][c] = 1 / A[r][c];
    for (j = 0; j <= n; j++)
      if (j != c) A[r][j] *= A[r][c];
    for (i = 0; i <= m; i++) {
      if (i != r) {
        for (j = 0; j <= n; j++)
          if (j != c) A[i][j] -= A[i][c] * A[r][j];
        A[i][c] = -A[i][c] * A[r][c];
      }
    }
  }
  int feasible(int m, int n, double A[507 + 7][507 + 7], int *B, int *N) {
    int r, c, i;
    double p, v;
    while (1) {
      for (p = 1000000007, i = 0; i < m; i++)
        if (A[i][n] < p) p = A[r = i][n];
      if (p > -(1e-12)) return 1;
      for (p = 0, i = 0; i < n; i++)
        if (A[r][i] < p) p = A[r][c = i];
      if (p > -(1e-12)) return 0;
      p = A[r][n] / A[r][c];
      for (i = r + 1; i < m; i++) {
        if (A[i][c] > (1e-12)) {
          v = A[i][n] / A[i][c];
          if (v < p) r = i, p = v;
        }
      }
      pivot(m, n, A, B, N, r, c);
    }
  }
  int simplex(int m, int n, double A[507 + 7][507 + 7], double *b,
              double &Ret) {
    int B[507 * 507 + 7], N[507 * 507 + 7], r, c, i;
    double p, v;
    for (i = 0; i < n; i++) N[i] = i;
    for (i = 0; i < m; i++) B[i] = n + i;
    if (!feasible(m, n, A, B, N)) return 0;
    while (1) {
      for (p = 0, i = 0; i < n; i++)
        if (A[m][i] > p) p = A[m][c = i];
      if (p < (1e-12)) {
        for (i = 0; i < n; i++)
          if (N[i] < n) b[N[i]] = 0;
        for (i = 0; i < m; i++)
          if (B[i] < n) b[B[i]] = A[i][n];
        Ret = -A[m][n];
        return 1;
      }
      for (p = 1000000007, i = 0; i < m; i++) {
        if (A[i][c] > (1e-12)) {
          v = A[i][n] / A[i][c];
          if (v < p) p = v, r = i;
        }
      }
      if (p == 1000000007) return -1;
      pivot(m, n, A, B, N, r, c);
    }
  }
};
Simplex smplx;
double a[507 + 7][507 + 7];
int n, X;
int c[505];
vector<int> adj[505], cst[505];
void go(int second, int u, int p, int d) {
  if (d > X) return;
  a[second][u] = -1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    int w = cst[u][i];
    if (v == p) continue;
    go(second, v, u, d + w);
  }
}
int kala;
int main() {
  cin >> n >> X;
  for (int i = 0; i < n; i++) cin >> c[i], kala += c[i];
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    cst[u].push_back(w);
    cst[v].push_back(w);
  }
  for (int i = 0; i < n; i++) go(i, i, i, 0), a[i][n] = -1;
  for (int i = 0; i < n; i++) a[n][i] = 1;
  a[n][n] = kala;
  for (int i = 0; i < n; i++) a[n + 1][i] = c[i];
  double ans = 0, x[505];
  int ret = smplx.simplex(n + 1, n, a, x, ans);
  if (ret == 0)
    cout << "-1" << endl;
  else {
    cout << kala - (int)(ans + .5) << endl;
  }
  return 0;
}
