#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vi = vector<int>;
using vvii = vector<vector<pair<int, int>>>;
const ld EPS = 1e-9;
struct LPSolver {
  int m, n;
  vi B, N;
  vvd D;
  LPSolver(const vvd &A, const vd &b, const vd &c)
      : m(((int)b.size())),
        n(((int)c.size())),
        N(n + 1),
        B(m),
        D(m + 2, vd(n + 2)) {
    for (int i = 0; i < (m); i++)
      for (int j = 0; j < (n); j++) D[i][j] = A[i][j];
    for (int i = 0; i < (m); i++) {
      B[i] = n + i;
      D[i][n] = -1;
      D[i][n + 1] = b[i];
    }
    for (int j = 0; j < (n); j++) {
      N[j] = j;
      D[m][j] = -c[j];
    }
    N[n] = -1;
    D[m + 1][n] = 1;
  }
  void Pivot(int r, int s) {
    for (int i = 0; i < (m + 2); i++)
      if (i != r && ((D[i][s] > EPS) || (D[i][s] < -EPS)))
        for (int j = 0; j < (n + 2); j++)
          if (j != s) D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < (n + 2); j++)
      if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < (m + 2); i++)
      if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s];
    swap(B[r], N[s]);
  }
  bool Simplex(int phase) {
    int x = phase == 1 ? m + 1 : m;
    while (true) {
      int s = -1;
      for (int j = 0; j < (n + 1); j++) {
        if (phase == 2 && N[j] == -1) continue;
        if (s == -1 || make_pair(D[x][j], N[j]) < make_pair(D[x][s], N[s]))
          s = j;
      }
      if (D[x][s] >= 0) return true;
      int r = -1;
      for (int i = 0; i < (m); i++) {
        if (D[i][s] < EPS) continue;
        if (r == -1 || make_pair(D[i][n + 1] / D[i][s], B[i]) <
                           make_pair(D[r][n + 1] / D[r][s], B[r]))
          r = i;
      }
      if (r == -1) return false;
      Pivot(r, s);
    }
  }
  ld Solve(vd &x) {
    int r = 0;
    for (int i = 0; i < (m); i++)
      if (D[i][n + 1] < D[r][n + 1]) r = i;
    if (D[r][n + 1] < -EPS) {
      Pivot(r, n);
      if (!Simplex(1) || D[m + 1][n + 1] < -EPS)
        return -numeric_limits<ld>::infinity();
      for (int i = 0; i < (m); i++)
        if (B[i] == -1) {
          int s = -1;
          for (int j = 0; j < (n + 1); j++)
            if (s == -1 || D[i][j] < D[i][s] ||
                D[i][j] == D[i][s] && N[j] < N[s])
              s = j;
          Pivot(i, s);
        }
    }
    if (!Simplex(2)) return numeric_limits<ld>::infinity();
    x = vd(n);
    for (int i = 0; i < (m); i++)
      if (B[i] < n) x[B[i]] = D[i][n + 1];
    return D[m][n + 1];
  }
};
vvii adj;
void dfs(vector<int> &d, int v, int p, int dist, int x) {
  d[v] = dist;
  for (auto pr : adj[v])
    if (pr.first != p && dist + pr.second <= x)
      dfs(d, pr.first, v, dist + pr.second, x);
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, x, color, u, v, w;
  cin >> n >> x;
  vvd A(n + 2, vd(n));
  vd B(n + 2, -1), C(n);
  B[n] = 0;
  for (int i = 0; i < (n); i++) {
    cin >> color;
    if (color == 0)
      C[i] = -1;
    else {
      C[i] = 0;
      B[n]++;
    }
  }
  adj.resize(n);
  vector<vector<int>> tr(n, vector<int>(n, x + 1));
  for (int i = 0; i < (n - 1); i++) {
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  for (int i = 0; i < (n); i++) dfs(tr[i], i, -1, 0, x);
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) A[i][j] = tr[i][j] > x ? 0 : -1;
  B[n + 1] = -B[n];
  B[n] = B[n];
  fill(A[n].begin(), A[n].end(), 1);
  fill(A[n + 1].begin(), A[n + 1].end(), -1);
  LPSolver LPS(A, B, C);
  vd X;
  int ans = round(-LPS.Solve(X));
  cout << (((int)X.size()) < n ? -1 : ans) << endl;
  return 0;
}
