#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
const int inf = 0x3f3f3f3f;
int dp[maxn][maxn][2];
int c[maxn], d[maxn];
vector<int> e[maxn];
int sz[maxn];
void dfs(int u) {
  sz[u] = 1;
  dp[u][0][0] = 0;
  dp[u][1][0] = c[u];
  dp[u][1][1] = c[u] - d[u];
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    dfs(v);
    for (int j = sz[u]; j >= 0; j--) {
      for (int k = 0; k <= sz[v]; k++) {
        dp[u][j + k][0] = min(dp[u][j + k][0], dp[u][j][0] + dp[v][k][0]);
        dp[u][j + k][1] = min(dp[u][j + k][1], dp[u][j][1] + dp[v][k][1]);
        dp[u][j + k][1] = min(dp[u][j + k][1], dp[u][j][1] + dp[v][k][0]);
      }
    }
    sz[u] += sz[v];
  }
}
int n, b;
int main() {
  memset(dp, inf, sizeof(dp));
  scanf("%d%d", &n, &b);
  scanf("%d%d", &c[1], &d[1]);
  for (int i = 2; i <= n; i++) {
    int u;
    scanf("%d%d%d", &c[i], &d[i], &u);
    e[u].push_back(i);
  }
  dfs(1);
  int ans = 0;
  for (int i = n; i >= 0; i--) {
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
