Language: C++

//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 101
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int n,X,D,sz[N],p[N],top[N]; ll m[N],f[2][N*N*N],g[N*N*N];
struct node{int v,c,id;}a[N]; int q[N*N*N];
bool operator<(node x,node y){return 1ll*x.c*y.v<1ll*x.v*y.c;}
int main()
{
	n=read(),X=read(),D=read(),m[1]=read(); sz[1]=1; top[1]=X;
	for(int i=2;i<=n;i++)	m[i]=read(),p[i]=read(),sz[i]=1;
	for(int i=n;i>1;i--)	sz[p[i]]+=sz[i],m[p[i]]+=m[i],m[i]=min(m[i],1000000001),top[i]=D;
	m[1]=min(1000000001,m[i]); for(int i=1;i<=n;i++)	a[i]=(node){sz[i],m[i],i};
	int cur=1,lst=0,s=0; memset(f[cur],63,sizeof(f[cur])); f[cur][0]=0;
	for(int i=1;i<=n;i++)
	{
		cur^=1,lst^=1; memset(f[cur],63,sizeof(f[cur]));
		int ctop=min(top[i],n); top[i]-=ctop;
		s+=ctop*sz[i];
		for(int j=0;j<sz[i];j++)
		{
			int hd=1,tl=0;
			for(int k=0;k*sz[i]+j<=s;k++)
			{
				int p=k*sz[i]+j;
				while(hd<=tl&&k-q[hd]>ctop)	hd++;
				while(hd<=tl&&g[tl]+1ll*(k-q[tl])*m[i]>=f[lst][p])	tl--;
				q[++tl]=k; g[tl]=f[lst][p];
				f[cur][p]=min(f[cur][p],g[hd]+1ll*(k-q[hd])*m[i]);
			}
		}
	}
	sort(a+1,a+n+1); ll ans=0;
	for(int i=0;i<=s;i++)	if(f[cur][i]<=X)
	{
		ll s1=0,s2=0;
		for(int j=1;j<=n;j++)
		{
			int x=a[j].id;
			ll nw=min(1ll*top[x],(X-f[cur][i]-s2)/a[j].c)*a[j].v;
			ans=max(ans,s1+i+nw);
			s1+=nw; s2+=1ll*top[x]*a[j].c;
			if(s2+f[cur][i]>X)	break;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:71: error: no matching function for call to 'min(long long int&, int)'
   24 |         for(int i=n;i>1;i--)    sz[p[i]]+=sz[i],m[p[i]]+=m[i],m[i]=min(m[i],1000000001),top[i]=D;
      |                                                                    ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:3:
/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:24:71: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   24 |         for(int i=n;i>1;i--)    sz[p[i]]+=sz[i],m[p[i]]+=m[i],m[i]=min(m[i],1000000001),top[i]=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,
                 from a.cc:4:
/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:24:71: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |         for(int i=n;i>1;i--)    sz[p[i]]+=sz[i],m[p[i]]+=m[i],m[i]=min(m[i],1000000001),top[i]=D;
      |                                                                    ~~~^~~~~~~~~~~~~~~~~
a.cc:25:31: error: 'i' was not declared in this scope
   25 |         m[1]=min(1000000001,m[i]); for(int i=1;i<=n;i++)        a[i]=(node){sz[i],m[i],i};
      |                               ^
a.cc:25:86: warning: narrowing conversion of 'm[i]' from 'long long int' to 'int' [-Wnarrowing]
   25 |         m[1]=min(1000000001,m[i]); for(int i=1;i<=n;i++)        a[i]=(node){sz[i],m[i],i};
      |                                                                                   ~~~^