#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
struct node {
  int nex, to;
} edge[5005 << 1];
int head[5005], tot;
int N, B;
inline void insert(int from, int to) {
  edge[++tot].nex = head[from];
  head[from] = tot;
  edge[tot].to = to;
}
int c[5005], d[5005];
int dp[2][5005][5005], siz[5005];
void dfs(int x) {
  dp[0][x][0] = 0;
  dp[0][x][1] = c[x];
  dp[1][x][1] = c[x] - d[x];
  siz[x] = 1;
  for (int i = head[x]; i; i = edge[i].nex) {
    dfs(edge[i].to);
    for (int j = siz[x]; j >= 0; j--)
      for (int k = 0; k <= siz[edge[i].to]; k++) {
        dp[0][x][j + k] =
            min(dp[0][x][j + k], dp[0][x][j] + dp[0][edge[i].to][k]);
        dp[1][x][j + k] =
            min(dp[1][x][j + k], dp[1][x][j] + dp[1][edge[i].to][k]);
        dp[1][x][j + k] =
            min(dp[1][x][j + k], dp[1][x][j] + dp[0][edge[i].to][k]);
      }
    siz[x] += siz[edge[i].to];
  }
}
int main() {
  memset(dp, 0x3f, sizeof(dp));
  read(N);
  read(B);
  read(c[1]);
  read(d[1]);
  int u;
  for (int i = 2; i <= N; i++) {
    read(c[i]);
    read(d[i]);
    read(u);
    insert(u, i);
  }
  dfs(1);
  int ans = N;
  while (dp[0][1][ans] > B && dp[1][1][ans] > B) ans--;
  cout << ans;
}
