Language: C++

//%std
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 53;
vector<int> G[N];
int n, x, d;
long long c[N], v[N], a[N], dp[N * N * N], id[N], ans;
void dfs (int u) {
	v[u] = 1;
	rep(i, 0, (signed)G[u].size() - 1) {
		dfs (G[u][i]);
		c[u] += c[G[u][i]], v[u] += v[G[u][i]];
	}
} 
void DP(long long x, long long y) { /*debug ("%lld %lld\n", x, y);*/ per(i, 125000, y) dp[i] = min (dp[i], dp[i - y] + x); }
int main ()
{
	scanf ("%d%d%d%lld", &n, &x, &d, &c[1]);
	rep (i, 2, n) { int p; scanf("%lld%d", &c[i], &p); G[p].push_back(i); }
	dfs (1);
	memset (dp, 0x3f, sizeof dp); dp[0] = 0;
	rep (i, 1, n) {
		id[i] = i;
		int lef = i == 1 ? 50 : min (50LL, d);
		for (int k = 1; k <= lef; lef -= k, k <<= 1) DP (1LL * c[i] * k, 1LL * v[i] * k);
		if (lef) DP (1LL * c[i] * lef, 1LL * v[i] * lef);
	}
	sort (id + 1, id + n + 1, [](int x, int y) { return 1LL * v[x] * c[y] > 1LL * v[y] * c[x]; });
	rep (p, 0, 125000) {
		if(dp[p] > x) break;
		int tans = p, tx = x - dp[p];
		rep (j, 1, n) { int i = id[j];
			long long cnt = min (1LL * tx / c[i], i == 1 ? 1000000000LL : (max (0LL, d - 50LL)));
			tx -= 1LL * cnt * c[i], tans += 1LL * cnt * v[i];
		}
		ans = max (ans, tans);
	}
	printf ("%lld\n", ans);
	return 0;
}













Compiler output:
a.cc: In function 'int main()':
a.cc:27:45: error: no matching function for call to 'min(long long int, int&)'
   27 |                 int lef = i == 1 ? 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:2:
/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:27:45: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   27 |                 int lef = i == 1 ? 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:27:45: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |                 int lef = i == 1 ? 50 : min (50LL, d);
      |                                         ~~~~^~~~~~~~~
a.cc:39:27: error: no matching function for call to 'max(long long int&, int&)'
   39 |                 ans = max (ans, tans);
      |                       ~~~~^~~~~~~~~~~
/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:39:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |                 ans = max (ans, tans);
      |                       ~~~~^~~~~~~~~~~
/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:39:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |                 ans = max (ans, tans);
      |                       ~~~~^~~~~~~~~~~