#include <bits/stdc++.h>
using namespace std;
int N, B;
int C[5005], D[5005];
vector<int> G[5005];
int Sz[5005];
int DP[2][5005][5005];
const int INF = 1000000005;
void Read() {
  scanf("%d%d", &N, &B);
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &C[i], &D[i]);
    if (i > 1) {
      int x;
      scanf("%d", &x);
      G[x].push_back(i);
    }
  }
}
void DFS(int node) {
  int cnt = 1;
  Sz[node] = 1;
  DP[0][node][1] = C[node];
  DP[1][node][1] = C[node] - D[node];
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i];
    DFS(neighb);
    Sz[node] += Sz[neighb];
    for (int j = cnt; j >= 0; j--) {
      for (int k = Sz[neighb]; k >= 1; k--) {
        if (DP[0][node][j + k] == 0) DP[0][node][j + k] = INF;
        DP[0][node][j + k] =
            min(DP[0][node][j + k], DP[0][node][j] + DP[0][neighb][k]);
        if (DP[0][node][j + k] > B) DP[0][node][j + k] = INF;
        if (DP[1][node][j + k] == 0) DP[1][node][j + k] = INF;
        if (j > 0)
          DP[1][node][j + k] =
              min(DP[1][node][j + k],
                  DP[1][node][j] + min(DP[0][neighb][k], DP[1][neighb][k]));
        if (DP[1][node][j + k] > B) DP[1][node][j + k] = INF;
      }
    }
    cnt += Sz[neighb];
  }
}
int main() {
  Read();
  DFS(1);
  for (int i = N; i >= 0; i--) {
    if (DP[0][1][i] <= B || DP[1][1][i] <= B) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}
