#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
using namespace std;
const int N=1e6+6; const ll INF=1e18;
struct data{ ll w; int s; }a[N];
bool cmp(data a,data b){ return a.s*b.w>b.s*a.w; }
int fa[N]; ll f[N];
void add(int m,int s,ll w,int t){
    int sk=0; t=min(t,m/s);
    for (int k=1;k*2<=t;k<<=1){
        sk+=k;
        per(j,m,s*k) if (f[j-s*k]!=INF) f[j]=min(f[j],f[j-s*k]+w*k);
    }
    int k=t-sk;
    per(j,m,s*k) if (f[j-s*k]!=INF) f[j]=min(f[j],f[j-s*k]+w*k);
}
int main(){
    int n,x,d; scanf("%d%d%d%lld",&n,&x,&d,&a[1].w);
    rep(i,2,n) scanf("%lld%d",&a[i].w,&fa[i]);
    per(i,n,1) a[fa[i]].s+=++a[i].s,a[fa[i]].w+=a[i].w;
    ll sum=a[1].w;
    int c=min(n,d);
    rep(i,1,c*n*n) f[i]=INF;
    add(c*n*n,a[1].s,a[1].w,n);
    rep(i,2,n) add(c*n*n,a[i].s,a[i].w,c);
    sort(a+1,a+1+n,cmp); int ans=0;
    rep(j,0,c*n*n){
        if (f[j]>x) continue;
        int t=j,r=x-f[j];
        rep(i,1,n)
            if (r>=a[i].w){
                int p=min(r/a[i].w,sum==a[i].w?INF:(ll)d-c);
                r-=p*a[i].w,t+=p*a[i].s;
            }
        ans=max(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}
