#include <bits/stdc++.h>
using namespace std;
long long c[2][(long long)(1e6 + 3)];
long long par[(long long)(1e6 + 3)], sz[(long long)(1e6 + 3)];
vector<long long> ch[(long long)(1e6 + 3)];
long long n, b;
vector<long long> v[2][(long long)(1e6 + 3)];
long long ind[(long long)(1e6 + 3)];
void merge(long long indu, vector<long long> &v0, vector<long long> &v1) {
  long long nu = v[1][indu].size() - 1;
  long long nc = v1.size() - 1;
  vector<long long> tmp1(nu + nc + 1, (long long)(1e18 + 3));
  tmp1[0] = 0;
  vector<long long> tmp0(nu + nc + 1, (long long)(1e18 + 3));
  tmp0[0] = 0;
  for (long long k = 1; k < nu + nc + 1; k++) {
    for (long long j = 0; j < nc + 1; j++) {
      if (j > k) break;
      if (j + nu < k) continue;
      tmp1[k] = min(tmp1[k], v[1][indu][k - j] + v1[j]);
      tmp1[k] = min(tmp1[k], v[1][indu][k - j] + v0[j]);
      tmp0[k] = min(tmp0[k], v[0][indu][k - j] + v0[j]);
    }
  }
  v[1][indu] = tmp1;
  v[0][indu] = tmp0;
}
void dfs(long long u) {
  sz[u] = 1;
  long long mx = -1, mxs = -1;
  for (long long i = 0; i < ch[u].size(); i++) {
    long long chd = ch[u][i];
    dfs(chd);
    if (sz[chd] > mxs) {
      mxs = sz[chd];
      mx = chd;
    }
    sz[u] += sz[chd];
  }
  if (mx != -1) {
    ind[u] = ind[mx];
  } else {
    v[0][ind[u]].push_back(0);
    v[1][ind[u]].push_back(0);
  }
  for (long long i = 0; i < ch[u].size(); i++) {
    long long chd = ch[u][i];
    if (chd == mx) continue;
    merge(ind[u], v[0][ind[chd]], v[1][ind[chd]]);
  }
  v[0][ind[u]].push_back((long long)(1e18 + 3));
  v[1][ind[u]].push_back((long long)(1e18 + 3));
  long long sz = v[0][ind[u]].size();
  for (long long i = sz - 1; i >= 1; i--) {
    v[0][ind[u]][i] = min(v[0][ind[u]][i], v[0][ind[u]][i - 1] + c[0][u]);
    v[1][ind[u]][i] = min(v[0][ind[u]][i], v[1][ind[u]][i - 1] + c[1][u]);
  }
}
void solve() {
  for (long long i = 0; i < (long long)(1e6 + 3); i++) ind[i] = i;
  cin >> n >> b;
  for (long long i = 0; i < n; i++) {
    cin >> c[0][i] >> c[1][i];
    c[1][i] = c[0][i] - c[1][i];
    if (i) {
      cin >> par[i];
      par[i]--;
      ch[par[i]].push_back(i);
    }
  }
  dfs(0);
  long long ans = 0;
  for (long long i = 0; i < n + 1; i++) {
    if (v[0][ind[0]][i] <= b || v[1][ind[0]][i] <= b) ans = i;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
