#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const int maxn=55;
int n,x,d,p[maxn],sz[maxn];LL m[maxn];

vector<LL> vs[maxn];
vector<pair<pair<int,LL>,int> >all;
LL dp[maxn*maxn*maxn];
bool cmp(pair<pair<int,LL>,int> a,pair<pair<int,LL>,int> b){return (a.ff.ff*b.ff.ss)>(a.ff.ss*b.ff.ff);}

int main()
{
	scanf("%d%d%d%lld",&n,&x,&d,m+1);
	for(int i=2;i<=n;i++)scanf("%lld%d",m+i,p+i);
	
	for(int i=1;i<=n;i++)sz[i]=1;
	for(int i=n;i>=2;i--)
	{
		sz[p[i]]+=sz[i];
		m[p[i]]+=m[i];
	}
	
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		int ub=min(d,50);if(i==1)ub=50;
		if(i==1)all.pb(mp(mp(sz[i],m[i]),inf));
		else if(d>ub)all.pb(mp(mp(sz[i],m[i]),d-ub));
		for(int j=0;j<ub;j++)
		{
			vs[sz[i]].pb(m[i]);
			sum+=sz[i];
		}
	}
	dp[0]=0;for(int i=1;i<=sum+1;i++)dp[i]=Linf;
	for(int i=1;i<=n;i++)if((int)vs[i].size())
	{
		sort(vs[i].begin(),vs[i].end());
		for(int j=sum;j>=0;j--)if(dp[j]!=Linf)
		{
			LL cur=dp[j];
			for(int k=0;k<(int)vs[i].size();k++)
			{
				cur+=vs[i][k];
				dp[j+(k+1)*i]=min(dp[j+(k+1)*i],cur);
			}
		}
	}
	
	sort(all.begin(),all.end(),cmp);
	int cur=0,cur_sum=0,cur_sz=0,ans=0;
	for(int i=sum;i>=0;i--)
	{
		dp[i]=min(dp[i],dp[i+1]);
		if(dp[i]<=x)
		{
			int rest=x-dp[i];
			while(cur<(int)all.size()&&(rest-cur_sum)/all[cur].ff.ss>=all[cur].ss)
			{
				cur_sum+=all[cur].ff.ss*all[cur].ss;
				cur_sz+=all[cur].ff.ff*all[cur].ss;
				cur++;
			}
			ans=max(0ll+ans,i+cur_sz+(cur<(int)all.size()?(rest-cur_sum)/all[cur].ff.ss*all[cur].ff.ff:0));
		}
	}
	printf("%d\n",ans);
	
	return 0;
}