#include <bits/stdc++.h>
using namespace std;
int n, b;
int f[5100][5100][2];
int C[5100], D[5100];
struct edge {
  int u, v, next;
} edges[5100 * 2];
int head[5100], nCount = 0;
void AddEdge(int U, int V) {
  edges[++nCount].u = U;
  edges[nCount].v = V;
  edges[nCount].next = head[U];
  head[U] = nCount;
}
int siz[5100];
void DFS(int u) {
  siz[u] = 1;
  f[u][0][0] = 0;
  f[u][1][0] = C[u];
  f[u][1][1] = C[u] - D[u];
  for (int p = head[u]; p != -1; p = edges[p].next) {
    int v = edges[p].v;
    DFS(v);
    for (int num = siz[u]; num >= 0; num--) {
      for (int num2 = 0; num2 <= siz[v]; num2++) {
        f[u][num + num2][0] =
            min(f[u][num + num2][0], f[u][num][0] + f[v][num2][0]);
        f[u][num + num2][1] =
            min(f[u][num + num2][1], f[u][num][1] + f[v][num2][0]);
        f[u][num + num2][1] =
            min(f[u][num + num2][1], f[u][num][1] + f[v][num2][1]);
      }
    }
    siz[u] += siz[v];
  }
}
int main() {
  memset(f, 0x3f, sizeof(f));
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &b);
  scanf("%d%d", &C[1], &D[1]);
  for (int i = 2; i <= n; i++) {
    int fa;
    scanf("%d%d%d", &C[i], &D[i], &fa);
    AddEdge(fa, i);
  }
  DFS(1);
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (f[1][i][0] <= b) ans = max(ans, i);
    if (f[1][i][1] <= b) ans = max(ans, i);
  }
  printf("%d\n", ans);
  return 0;
}
