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;
using ld = 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;
inline bool lessPair(ld d1, int i1, ld d2, int i2) {
  return abs(d1 - d2) > EPS ? d1 < d2 : i1 < i2;
}
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())),
        B(m + 1),
        N(n + 1),
        D(m + 1, vd(n + 1, 0)) {
    for (int i = 0; i < (m); i++) {
      for (int j = 0; j < (n); j++) D[i + 1][j] = A[i][j];
      D[i + 1][n] = b[i];
    }
    for (int i = 0; i < (n); i++) D[0][i] = -c[i];
    for (int i = 0; i < (m + 1); i++) B[i] = -i;
    for (int j = 0; j < (n + 1); j++) N[j] = j;
  }
  void Pivot(int r, int s) {
    for (int i = 0; i < (m + 1); i++)
      if (i != r && ((D[i][s] > EPS) || (D[i][s] < -EPS)))
        for (int j = 0; j < (n + 1); j++)
          if (j != s) D[i][j] -= D[r][j] * D[i][s] / D[r][s];
    for (int j = 0; j < (n + 1); j++)
      if (j != s) D[r][j] /= D[r][s];
    for (int i = 0; i < (m + 1); i++)
      if (i != r) D[i][s] /= -D[r][s];
    D[r][s] = 1.0 / D[r][s];
    swap(B[r], N[s]);
  }
  ld Solve(vector<ld> &x) {
    while (true) {
      int ii = 1, jj = 0;
      for (int i = 1; i <= (m); i++)
        if (lessPair(D[i][n], B[i], D[ii][n], B[ii])) ii = i;
      if (D[ii][n] > -EPS) break;
      for (int j = 0; j < (n); j++)
        if (D[ii][j] < D[ii][jj]) jj = j;
      if (D[ii][jj] > -EPS) return -numeric_limits<ld>::infinity();
      Pivot(ii, jj);
    }
    while (true) {
      int ii = 1, jj = 0;
      for (int j = 0; j < (n); j++)
        if (lessPair(D[0][j], N[j], D[0][jj], N[jj])) jj = j;
      if (D[0][jj] > -EPS) break;
      for (int i = 1; i <= (m); i++)
        if (D[i][jj] > EPS &&
            (D[ii][jj] < EPS ||
             lessPair(D[i][n] / D[i][jj], B[i], D[ii][n] / D[ii][jj], B[ii])))
          ii = i;
      if (D[ii][jj] < EPS) return numeric_limits<ld>::infinity();
      Pivot(ii, jj);
    }
    x.assign(n, 0);
    for (int i = 1; i <= (m); i++)
      if (B[i] >= 0) x[B[i]] = D[i][n];
    return D[0][n];
  }
};
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];
  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;
}
