#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
double INF = 1e30, eps = 1e-6;
int sig(double x) { return abs(x) < eps ? 0 : (x > 0 ? 1 : -1); }
int c[502], x, n, A[502][10 + 1], dist[502][502], level[502];
long long int dfr[502];
vector<pair<int, long long int>> adj[502];
double a_[502][502], b_[502], c_[502];
void dfs(int base, int curr, int par = -1, long long int w = 0, int l = 0) {
  if (w <= x) dist[base][curr] = 1;
  level[curr] = l;
  for (auto nxt : adj[curr])
    if (nxt.first != par) dfs(base, nxt.first, curr, nxt.second + w, l + 1);
}
int lca(int p, int q) {
  if (level[p] < level[q]) swap(p, q);
  for (int i = ceil(log2(n)); i >= 0; i--)
    if (level[p] - (1 << i) >= level[q]) p = A[p][i];
  if (p == q) return p;
  for (int i = ceil(log2(n)); i >= 0; i--)
    if (A[p][i] != -1 && A[p][i] != A[q][i]) {
      p = A[p][i];
      q = A[q][i];
    }
  return A[p][0];
}
struct Simplex {
  set<int> N;
  set<int> B;
  double b[2 * 502];
  double A[2 * 502][2 * 502];
  double c[2 * 502];
  double v;
  int n, m;
  double c_backup[2 * 502];
  int init(double _A[502][502], double _b[502], double _c[502], int _n,
           int _m) {
    N.clear();
    B.clear();
    n = _n;
    m = _m;
    for (int j = 0; j < n; j++) N.insert(j);
    for (int i = n; i < n + m; i++) B.insert(i);
    for (int i = n; i < n + m; i++) b[i] = _b[i - n];
    memset(A, 0, sizeof(A));
    for (int i = n; i < n + m; i++)
      for (int j = 0; j < n; j++) A[i][j] = _A[i - n][j];
    for (int j = 0; j < n; j++) c[j] = _c[j];
    v = 0;
    int l = n;
    for (int i = n + 1; i < n + m; i++)
      if (b[i] < b[l]) l = i;
    if (sig(b[l]) < 0) {
      N.insert(n + m);
      memcpy(c_backup, c, sizeof(c));
      memset(c, 0, sizeof(c));
      c[n + m] = -1;
      for (int i = n; i < n + m; i++) A[i][n + m] = -1;
      pivot(n + m, l);
      double r = work();
      if (sig(r) != 0) return -1;
      B.insert(n + m + 1);
      if (N.find(n + m) != N.end()) {
        A[n + m + 1][n + m] = 1.0;
      } else {
        for (__typeof(N.begin()) j = N.begin(); j != N.end(); ++j)
          A[n + m + 1][*j] = -A[n + m][*j];
        b[n + m + 1] = -b[n + m];
      }
      memcpy(c, c_backup, sizeof(c));
      for (int i = 0; i < n; i++)
        if (B.find(i) != B.end()) {
          v += c[i] * b[i];
          for (__typeof(N.begin()) j = N.begin(); j != N.end(); ++j)
            c[*j] -= c[i] * A[i][*j];
          c[i] = 0.0;
        }
    }
    return 0;
  }
  void pivot(int e, int l) {
    static int que[502], qr;
    A[e][l] = 1.0 / A[l][e];
    qr = 0;
    for (__typeof(N.begin()) j = N.begin(); j != N.end(); ++j)
      if (*j != e && sig(A[l][*j]))
        A[e][*j] = A[l][*j] / A[l][e], que[qr++] = *j;
    b[e] = b[l] / A[l][e];
    memset(A[l], 0, sizeof(A[l]));
    b[l] = 0;
    B.erase(l);
    B.insert(e);
    N.erase(e);
    N.insert(l);
    que[qr++] = l;
    for (__typeof(B.begin()) _i = B.begin(); _i != B.end(); ++_i)
      if (*_i != e && sig(A[*_i][e])) {
        int i = *_i;
        b[i] = b[i] - A[i][e] * b[e];
        for (int qi = 0; qi < qr; qi++) {
          int j = que[qi];
          A[i][j] -= A[i][e] * A[e][j];
        }
        A[i][e] = 0.0;
      }
    v += c[e] * b[e];
    for (__typeof(N.begin()) j = N.begin(); j != N.end(); ++j)
      c[*j] -= c[e] * A[e][*j];
    c[e] = 0.0;
  }
  double work() {
    while (1) {
      int e = -1;
      double maxc = -1000000007;
      for (__typeof(N.begin()) j = N.begin(); j != N.end(); ++j)
        if (c[*j] > maxc) {
          maxc = c[*j];
          e = *j;
        }
      if (sig(maxc) <= 0) break;
      double delta = 1000000007;
      int l;
      for (__typeof(B.begin()) _i = B.begin(); _i != B.end(); ++_i) {
        int i = *_i;
        if (sig(A[i][e]) > 0) {
          double t_delta = b[i] / A[i][e];
          if (delta > t_delta) {
            delta = t_delta;
            l = i;
          }
        }
      }
      if (delta == 1000000007) return 1000000007;
      pivot(e, l);
    }
    return v;
  }
} simplex;
int readint() {
  char cc = getchar();
  while (cc < '0' || cc > '9') {
    cc = getchar();
  }
  int ans = 0;
  while (cc >= '0' && cc <= '9') {
    ans = ans * 10 + cc - '0';
    cc = getchar();
  }
  return ans;
}
int main() {
  cin >> n;
  cin >> x;
  int B = 0;
  for (int i = 0; i < n; i++) c[i] = readint(), B += c[i] ? 1 : 0;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    long long int w;
    cin >> x >> y >> w;
    adj[--x].push_back({--y, w});
    adj[y].push_back({x, w});
  }
  for (int i = 0; i < n; i++) {
    dfs(i, i);
  }
  for (int i = 0; i < n; i++) {
    c_[i] = ((c[i] == 1 ? 1 : 0));
    a_[n][i] = 1;
  }
  for (int i = 0; i < n; i++) {
    vector<long double> temp;
    int sum = 0;
    for (int j = 0; j < n; j++) {
      a_[i][j] = (-dist[i][j]);
      sum += dist[i][j];
    }
    b_[i] = (-1);
  }
  b_[n] = B;
  int flag = simplex.init(a_, b_, c_, n, n + 1);
  if (flag) {
    puts("-1");
  } else {
    double sim = simplex.work();
    int res = (int)(sim + eps);
    printf("%d\n", B - res);
  }
  return 0;
};
