#include <bits/stdc++.h>   using namespace std;   vector<int> g[5005];   int h[5005][5005], siz[5005];   int f[5005][5005], fa;   int n, m, a[5005], b[5005], k;   inline int min(const int x, const int y) { return x > y ? y : x; }   void dfs(int x) {     int to;     siz[x] = 1;     h[x][1] = b[x];     f[x][0] = 0, f[x][1] = a[x];     for (int i = g[x].size() - 1; i >= 0; i--) {       to = g[x][i];       dfs(to);       for (int j = siz[x]; j >= 0; j--) {         for (int u = 1; u <= siz[to]; u++) {           if (f[to][u] > k && h[to][u] > k) break;           if (f[to][u] <= k) {             h[x][j + u] = min(h[x][j + u], f[to][u] + h[x][j]);             f[x][j + u] = min(f[x][j + u], f[to][u] + f[x][j]);           }           if (h[to][u] <= k) h[x][j + u] = min(h[x][j + u], h[to][u] + h[x][j]);         }       }       siz[x] += siz[to];     }   }   int main() {     memset(h, 0x3f, sizeof(h));     memset(f, 0x3f, sizeof(f));     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , a + i, b + i);       b[i] = a[i] - b[i];       if (i > 1) {         scanf( %d , &fa);         g[fa].push_back(i);       }     }     dfs(1);     for (int i = n; i >= 0; i--)       if (h[1][i] <= k || f[1][i] <= k) {         printf( %d n , i);         return 0;       }     return 0;   }   