#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
void yes(bool y) { cout << (y ? "YES\n" : "NO\n"); }
template <typename T>
ostream& operator<<(ostream& os, vector<T> const& v) {
  for (T x : v) {
    os << x << ' ';
  }
  os << '\n';
  return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) {
    is >> x;
  }
  return is;
}
vector<int> sz, c, d;
array<array<array<int, 2>, 5001>, 5000> dp;
vector<vector<int>> adj;
const int with = true;
const int wout = false;
void dfs(int u) {
  dp[u][1][with] = c[u] - d[u];
  dp[u][1][wout] = c[u];
  dp[u][0][wout] = 0;
  sz[u] = 1;
  for (int v : adj[u]) {
    dfs(v);
    for (int j = sz[u]; j >= 0; --j) {
      for (int k = sz[v]; k >= 0; --k) {
        dp[u][j + k][wout] =
            min(dp[u][j + k][wout], dp[u][j][wout] + dp[v][k][wout]);
        dp[u][j + k][with] =
            min(dp[u][j + k][with],
                dp[u][j][with] + min(dp[v][k][wout], dp[v][k][with]));
      }
    }
    sz[u] += sz[v];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, b;
  cin >> n >> b;
  adj.resize(n);
  c.resize(n);
  d.resize(n);
  sz.resize(n);
  const int inf = 1e9 + 5;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= n; ++j) {
      for (int k = 0; k < 2; ++k) {
        dp[i][j][k] = inf;
      }
    }
  }
  for (int i = 0, x; i < n; ++i) {
    cin >> c[i] >> d[i];
    if (i) cin >> x;
    if (i) adj[x - 1].push_back(i);
  }
  dfs(0);
  for (int i = n; i >= 0; --i) {
    if (dp[0][i][with] <= b || dp[0][i][wout] <= b) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "0\n";
}
