Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const ll INF = 1ll << 60;
const double EPS = 1e-8;
const int MOD = 1000000007;

int T, n, m;
ll X, D;
int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    cin >> n >> X >> D;
    vi c(n, 1), p(n, -1), w(n);
    cin >> w[0];
    REPS(i, n - 1) {
        cin >> w[i] >> p[i]; p[i] --;
    }
    RREPS(i, n - 1) {
        c[p[i]] += c[i];
        w[p[i]] += w[i];
    }
    vector<tuple<ll, ll, ll>> item, item3;
    REP(i, n) {
        item.emplace_back(c[i], w[i], i ? D : MOD);
    }
    sort(RALL(item), [](tuple<ll, ll, ll> x, tuple<ll, ll, ll> y){
        return get<0>(x) * get<1>(y) < get<1>(x) * get<0>(y);
    });
    vector<pll> item2;
    for(auto &it : item) {
        ll c, w, d; tie(c, w, d) = it;
        ll t = min(d, 50);
        if(d - t) item3.emplace_back(c, w, d - t);
        REP(j, 20) {
            if (t >= (1 << j)) {
                t -= 1 << j;
                item2.emplace_back(c * (1 << j), w * (1 << j));
            }
        }
        if (t) item2.emplace_back(c * t, w * t);
    }
    vector<ll> dp(125001, MOD);
    dp[0] = 0;
    for (auto it : item2) {
        ll c, w; tie(c, w) = it;
        RREP(i, (int)dp.size() - c) {
            dp[i + c] = min(dp[i + c], dp[i] + w);
        }
    }
    ll ans = 0;
    REP(i, dp.size()) {
        ll remainX = X - dp[i];
        if (remainX < 0) continue;
        ll sum = i;
        for(auto &it : item3) {
            ll c, w, d;
            tie(c, w, d) = it;
            ll t = min(d, remainX / w);
            remainX -= t * w;
            sum += t * c;
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:65:19: error: no matching function for call to 'min(ll&, int)'
   65 |         ll t = min(d, 50);
      |                ~~~^~~~~~~
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:65:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   65 |         ll t = min(d, 50);
      |                ~~~^~~~~~~
/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:65:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   65 |         ll t = min(d, 50);
      |                ~~~^~~~~~~