#include<bits/stdc++.h>
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N   = 52;

pair < double , pp > P[N];
int dp[N*N*N],val[N],W[N],par[N],n,d,budget,K,i,j,k,l;
deque < pp > Q;

int kesv,kesw,ans,cur,valmax,t;

bool cmp(pp a, pp b){
    return a.st * b.nd > b.st * a.nd;
}

signed main(){

    cin >> n >> budget >> d >> W[1];
    for(i=2;i<=n;i++) cin >> W[i] >> par[i];
    for(i=n; i ;i--) { W[ par[i] ] += W[i]; val[ par[i] ] += ++val[i]; }

    if(val[1] != n) assert(0);

    K = min(d , n);
    valmax = n * n * n + 1;


    memset(dp , 11 , sizeof dp);
    dp[0] = 0;
    for(i=1;i<=n;i++){
        for(j=0;j<val[i];j++){
            Q.clear();
            for(l=0,k=j;k<valmax;k+=val[i],l--){
                t = dp[k];
                if(Q.size() && Q.front().nd - l == K+1) Q.pop_front();
                if(Q.size()) dp[k] = min(dp[k] , Q.front().st - l * W[i]);

                for(; Q.size() && Q.back().st > t+l*W[i] ;) Q.pop_back();
                Q.pb(mp(t+l*W[i] , l));
            }
        }
    }

    for(i=1;i<=n;i++) P[i] = mp(1.0*val[i]/W[i],mp(val[i] , W[i]));
    sort(P+1 , P+n+1);
    reverse(P+1 , P+n+1);
    for(i=valmax-1; i>=0 ;i--){
        if(dp[i] > budget) continue;
        kesv = kesw = 0;
        for(cur=1; P[cur].nd.st != n && (budget - dp[i] - kesw) >= P[cur].nd.nd * (d - K); cur++){
            if(cur > n) assert(0);
            kesw += P[cur].nd.nd * (d - K);
            kesv += P[cur].nd.st * (d - K);
        }

        ans = max(ans , i + kesv + (budget - dp[i] - kesw) / P[cur].nd.nd * P[cur].nd.st);
    }

    cout << ans << endl;
    return 0;
}