Language: C++

#include <bits/stdc++.h>
using namespace std;

int64_t N, V[50];
int64_t X, D, M[50], W[50];
vector<int> child[50];
const int MAX = 50*50*50;
int64_t dp[MAX+1];

void dfs(int i){
    V[i] = 1;
    W[i] = M[i];
    for(auto j : child[i]){
        dfs(j);
        V[i] += V[j];
        W[i] += W[j];
    }
}

int main(){
    cin >> N >> X >> D;
    for(int i=0; i<N; i++){
        cin >> M[i];
        if(i>0){
            int p;
            cin >> p;
            child[p-1].push_back(i);
        }
    }

    dfs(0);
    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [](int i, int j){ return V[i] * W[j] > V[j] * W[i];});

    int64_t INF = 1e10;
    fill(begin(dp), end(dp), INF);
    dp[0] = 0;
    for(int i=0; i<N; i++){
        int num = (i==0 ? 50 : min(50LL, D));
        for(int k=32; k>0; k /= 2){
            if(num < k) continue;
            num -= k;
            int64_t wdiff = W[i] * k;
            int vdiff = V[i] * k;
            for(int j=MAX; j>=vdiff; j--){
                dp[j] = min(dp[j], dp[j-vdiff] + wdiff);
            }
        }
    }

    int ans = 0;
    for(int j=0; j<=MAX; j++){
        int64_t w = dp[j];
        int v = j;
        if(w > X) continue;
        for(auto i : order){
            int64_t num = (i==0 ? INF : max(0LL, D-50));
            int use = min(num, (X-w)/W[i]);
            v += use * V[i];
            w += use * W[i];
        }
        ans = max(ans, v);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:35: error: no matching function for call to 'min(long long int, int64_t&)'
   40 |         int num = (i==0 ? 50 : min(50LL, D));
      |                                ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:40:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   40 |         int num = (i==0 ? 50 : min(50LL, D));
      |                                ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:40:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   40 |         int num = (i==0 ? 50 : min(50LL, D));
      |                                ~~~^~~~~~~~~
a.cc:58:44: error: no matching function for call to 'max(long long int, int64_t)'
   58 |             int64_t num = (i==0 ? INF : max(0LL, D-50));
      |                                         ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:58:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'})
   58 |             int64_t num = (i==0 ? INF : max(0LL, D-50));
      |                                         ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:58:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   58 |             int64_t num = (i==0 ? INF : max(0LL, D-50));
      |                                         ~~~^~~~~~~~~~~