func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   int n, B, c0[5010], c1[5010];   vector<int> e[5010];   vector<long long> f[5010], g[5010];   void combine(vector<long long>& a, const vector<long long>& b) {     int la = a.size(), lb = b.size(), lc = la + lb - 1;     vector<long long> c(lc);     for (int i = 0; i < lc; ++i) c[i] = inf;     for (int i = 0; i < la; ++i)       for (int j = 0; j < lb; ++j) c[i + j] = min(c[i + j], a[i] + b[j]);     a = c;   }   void dfs(int x) {     vector<long long> a, b;     a.push_back(0);     b.push_back(0);     for (int v : e[x]) {       dfs(v);       combine(a, f[v]);       combine(b, g[v]);     }     f[x].push_back(0);     for (int i = 0; i < a.size(); ++i) {       f[x].push_back(a[i] + c0[x]);     }     g[x] = b;     g[x].push_back(inf);     for (int i = 0; i < b.size(); ++i) {       g[x][i + 1] = min(g[x][i + 1], b[i] + c1[x]);     }     for (int i = 0; i < b.size(); ++i) {       f[x][i] = min(f[x][i], g[x][i]);     }   }   int main() {     scanf( %d%d , &n, &B);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &c1[i], &c0[i]);       c0[i] = c1[i] - c0[i];       int fa;       if (i != 1) scanf( %d , &fa), e[fa].push_back(i);     }     dfs(1);     int ans = 0;     for (int i = 0; i < f[1].size(); ++i)       if (f[1][i] <= B) ans = i;     for (int i = ans + 1; i <= (int)g[1].size() - 1; ++i)       if (g[1][i] <= B) ans = i;     printf( %d n , ans);     return 0;   }   