#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, b;
int get(int x) {
  if (x > b)
    return b + 1;
  else
    return x;
}
int c[N], d[N], sz[N];
int dp[N][N][2];
vector<vector<int> > g(N);
void dfs(int v) {
  vector<int> p[2];
  for (int to : g[v]) {
    dfs(to);
    p[0].resize(sz[v] + sz[to] + 1, b + 1);
    p[1].resize(sz[v] + sz[to] + 1, b + 1);
    for (int i = 0; i <= sz[v]; ++i) {
      for (int j = 0; j <= sz[to]; ++j) {
        p[0][i + j] = min(p[0][i + j], dp[v][i][0] + dp[to][j][0]);
        p[0][i + j] = get(p[0][i + j]);
        p[1][i + j] = min(
            p[1][i + j], min(p[0][i + j], min(dp[v][i][0], dp[v][i][1]) +
                                              min(dp[to][j][0], dp[to][j][1])));
        p[1][i + j] = get(p[1][i + j]);
      }
    }
    for (int i = 0; i < p[0].size(); ++i) {
      dp[v][i][0] = p[0][i];
      dp[v][i][1] = p[1][i];
    }
    sz[v] += sz[to];
  }
  sz[v]++;
  dp[v][sz[v]][0] = dp[v][sz[v]][1] = b + 1;
  for (int i = sz[v]; i > 0; --i) {
    dp[v][i][0] = min(dp[v][i][0], dp[v][i - 1][0] + c[v]);
    dp[v][i][0] = get(dp[v][i][0]);
    dp[v][i][1] = dp[v][i - 1][1] + d[v];
    dp[v][i][1] = get(dp[v][i][1]);
  }
  dp[v][0][1] = b + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> b;
  for (int i = 1; i <= n; ++i) {
    int ci, di;
    cin >> ci >> di;
    c[i] = ci;
    d[i] = c[i] - di;
    if (i > 1) {
      int p;
      cin >> p;
      g[p].push_back(i);
    }
  }
  dfs(1);
  for (int i = sz[1]; i >= 0; --i) {
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
