You have a weighted tree, consisting of n vertices. Each vertex is either painted black or is painted red. A red and black tree is called beautiful, if for any its vertex we can find a black vertex at distance at most x.

The distance between two nodes is the shortest path between them.

You have a red and black tree. Your task is to make it beautiful in the minimum number of color swap operations. In one color swap operation, you can choose two vertices of different colors and paint each of them the other color. In other words, if you choose a red vertex p and a black vertex q, then in one operation you are allowed to paint p black and paint q red.

Print the minimum number of required actions.

Input

The first line contains two integers n and x (2 ≤ n ≤ 500; 1 ≤ x ≤ 109). The next line contains n integers, each of them is either a zero or one. If the i-th number equals 1, then vertex i of the tree is black, otherwise vertex i is red. Next n - 1 lines contain the tree edges. The j-th line contains integers uj vj wj (1 ≤ uj, vj ≤ n; uj ≠ vj; 1 ≤ wj ≤ 109) which means that the tree has an edge of weight wj between vertices vj and uj.

Assume that the tree vertices are numbered from 1 to n.

Output

Print a single integer — the minimum number of required swap operations.

If it is impossible to get a beautiful tree at any number of operations, print -1.

Examples

Input

3 2
1 0 0
1 2 2
2 3 2


Output

1


Input

4 2
0 1 0 0
1 2 2
2 3 2
3 4 2


Output

-1
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % M;
    a = a * a % M;
    b >>= 1;
  }
  return res;
}
const long double eps = 1e-8, inf = 1 / .0;
struct LPSolver {
  int m, n;
  vector<int> N, B;
  vector<vector<long double>> D;
  LPSolver(const vector<vector<long double>> &A, const vector<long double> &b,
           const vector<long double> &c)
      : m((int)(b).size()),
        n((int)(c).size()),
        N(n + 1),
        B(m),
        D(m + 2, vector<long double>(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) {
    long double *a = D[r].data(), inv = 1 / a[s];
    for (int i = (0); i < (m + 2); i++)
      if (i != r && abs(D[i][s]) > eps) {
        long double *b = D[i].data(), inv2 = b[s] * inv;
        for (int j = (0); j < (n + 2); j++) b[j] -= a[j] * inv2;
        b[s] = a[s] * inv2;
      }
    for (int j = (0); j < (n + 2); j++)
      if (j != s) D[r][j] *= inv;
    for (int i = (0); i < (m + 2); i++)
      if (i != r) D[i][s] *= -inv;
    D[r][s] = inv;
    swap(B[r], N[s]);
  }
  bool simplex(int phase) {
    int x = m + phase - 1;
    for (;;) {
      int s = -1;
      for (int j = (0); j < (n + 1); j++)
        if (N[j] != -phase)
          if (s == -1 || make_pair(D[x][j], N[j]) < make_pair(D[x][s], N[s]))
            s = j;
      if (D[x][s] >= -eps) 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);
    }
  }
  long double solve(vector<long double> &x) {
    int r = 0;
    for (int i = (1); 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(2) || D[m + 1][n + 1] < -eps) return -inf;
      for (int i = (0); i < (m); i++)
        if (B[i] == -1) {
          int s = 0;
          for (int j = (1); j < (n + 1); j++)
            if (s == -1 || make_pair(D[i][j], N[j]) < make_pair(D[i][s], N[s]))
              s = j;
          pivot(i, s);
        }
    }
    bool ok = simplex(1);
    x = vector<long double>(n);
    for (int i = (0); i < (m); i++)
      if (B[i] < n) x[B[i]] = D[i][n + 1];
    return ok ? D[m][n + 1] : inf;
  }
};
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> adj[n];
  vector<int> col(n);
  int q_r = 0;
  for (int i = 0; i < n; i++) {
    cin >> col[i];
    if (col[i] == 0) q_r++;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].emplace_back(v, w);
    adj[v].emplace_back(u, w);
  }
  vector<vector<bool>> D(n, vector<bool>(n));
  function<void(int, int, int, int)> dfs = [&](int u, int root, int d, int p) {
    D[root][u] = 1;
    for (pair<int, int> v : adj[u]) {
      if (v.first == p) continue;
      if (d + v.second <= k) {
        dfs(v.first, root, d + v.second, u);
      }
    }
  };
  for (int i = 0; i < n; i++) {
    dfs(i, i, 0, i);
  }
  vector<long double> b(2 * n + 1), c(n), x;
  vector<vector<long double>> A(2 * n + 1, vector<long double>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      A[i][j] = -D[i][j];
    }
    b[i] = -1;
  }
  for (int i = n; i < 2 * n; i++) {
    A[i][i - n] = -1;
  }
  for (int i = 0; i < n; i++) {
    A[2 * n][i] = 1;
  }
  b[2 * n] = n - q_r;
  for (int i = 0; i < n; i++) {
    c[i] = -(!col[i]);
  }
  long double res = LPSolver(A, b, c).solve(x);
  if (res == -inf) {
    cout << -1 << "\n";
  } else
    cout << (long long)round(-res) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
