Language: C++

#include <bits/stdc++.h>
#define int long long
#define inf (1ll<<60)
using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,X,D,w[100],v[100],p[100];
int F[52][52*52*52],id[52];
int wss[100],vs[100],sumw[100],sumv[100];
inline bool cmp(const int a,const int b)
{
	return v[a]*w[b]>v[b]*w[a];
}
inline int calc(int xx)
{
	int gs=lower_bound(sumw+1,sumw+1+n,xx+1)-sumw-1;
	int s=xx-sumw[gs];
	if(gs>=n) return sumv[gs];
	return sumv[gs]+min(max(0,D-n),s/wss[gs+1])*vs[gs+1];
}
signed main()
{
	n=read(); X=read(); D=read(); 
	for(int i=1;i<=n;i++) v[i]=1;
	w[1]=read(); for(int i=2;i<=n;i++)
		w[i]=read(), p[i]=read();
	for(int i=n;i>1;i--)
		w[p[i]]+=w[i], v[p[i]]+=v[i];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n*n*n;j++)
			F[i][j]=inf; F[0][0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=n*n*n;j++) if(F[i][j]!=inf)
		{
			for(int t=0;j+v[i]*t<=n*n*n&&t<=n;t++)
				F[i+1][j+v[i]*t]=min(F[i+1][j+v[i]*t],F[i][j]+w[i]*t);
		}
	}
	for(int i=1;i<=n;i++) id[i]=i;
	sort(id+1,id+1+n,cmp);
	for(int i=1;i<=n;i++)
		wss[i]=w[id[i]], vs[i]=v[id[i]],
		sumw[i]=max(0ll,D-n)*wss[i], 
		sumv[i]=max(0ll,D-n)*vs[i];
	for(int i=1;i<=n;i++)
		sumw[i]+=sumw[i-1], 
		sumv[i]+=sumv[i-1];
	int Ans=0; for(int i=0;i<=n*n*n;i++)
		if(X-F[n][i]>=0) Ans=max(Ans,calc(X-F[n][i])+i);
	cout << Ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'long long int calc(long long int)':
a.cc:25:32: error: no matching function for call to 'max(int, long long int)'
   25 |         return sumv[gs]+min(max(0,D-n),s/wss[gs+1])*vs[gs+1];
      |                             ~~~^~~~~~~
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: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:25:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   25 |         return sumv[gs]+min(max(0,D-n),s/wss[gs+1])*vs[gs+1];
      |                             ~~~^~~~~~~
/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
In file included from /usr/include/c++/14/algorithm:61:
/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:25:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   25 |         return sumv[gs]+min(max(0,D-n),s/wss[gs+1])*vs[gs+1];
      |                             ~~~^~~~~~~