#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


class TreeSize{
public:
  int V;
  int root;
  vector<vector<int> > G;
  vector<int> w;
  vector<int> sz;
  int ok;
  TreeSize():V(-1){};
  TreeSize(int V,int root = 0):V(V),root(root),G(V),w(V,1),sz(V,0),ok(0){}
  void resize(int n){*this = TreeSize(n);}
  int& operator [](int i){return w[i];}
  
  void add_edge(int a,int b){
    ok = false;
    assert(a < V && b < V);
    assert(a >= 0 && b >= 0);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  void build(int root=-1){
    ok = 1;
    if(root != -1) this->root = root;
    dfs(this->root,-1);
  }
  
  int dfs(int pos,int pre = -1){
    sz[pos] = w[pos];
    for(int to:G[pos]) if(to != pre) sz[pos] += dfs(to, pos);
    return sz[pos];
  }
  int size(int i){assert(ok);return sz[i];}
};


vector<int> DP(vector<int> V, vector<int> W, vector<int> K){
  int n = V.size();
  int N = 51*51*51;
  vector<int> dp(N+1, INF);
  dp[0] = 0;
  
  for(int i=0;i<n;i++){
    int v = V[i];
    int w = W[i];
    int k = K[i];
    for(int t=min(k, 1LL); k>0 ; k-=t, t = min(t*2, k)){    
      for(int j=N;j>=0;j--){
        if(j - v * t < 0) continue;
        Min(dp[j], dp[j - v * t] + w*t);
      }
    }    
  }
  return dp;
}

int calc(vector<int> &V,vector<int> &W, vector<int> &K, vector<int> &Idx,int X){
  int res = 0;
  for(int i:Idx){
    int v = V[i];
    int w = W[i];
    int k = K[i];
    int num = min(k, X/w);
    res += v * num;
    X -= w * num;
  }
  return res;
}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n,X,D;
  cin>>n>>X>>D;
  TreeSize A(n), B(n); // |G[i]|, |W[i]|

  cin>>B[0];
  for(int i=1;i<n;i++){
    int m,p;
    cin>>m>>p; p--;
    A.add_edge(i,p);
    B.add_edge(i,p);
    B[i] = m;
  }

  A.build();
  B.build();
  
  int ans = -INF;
  {
    vector<int> dp;
    vector<int> V(n), W(n), K(n);
    for(int i=0;i<n;i++) V[i] = A.size(i);
    for(int i=0;i<n;i++) W[i] = B.size(i);
    K[0] = 50;
    for(int i=1;i<n;i++) K[i] = min(50LL,D);

    vector<int> Idx(n);
    for(int i=0;i<n;i++) Idx[i] = i;

    dp = DP(V,W,K); 
    int N = 51*51*51;
    
    K[0] = INF;
    for(int i=1;i<n;i++) K[i] = D - K[i];

    sort(Idx.begin(),Idx.end(), [&](int i,int j){
        double a = 1.0 * V[i]/W[i];
        double b = 1.0 * V[j]/W[j];
        if(a != b) return a > b;
        return W[i] > W[j];
      });
    
   
    for(int i=0;i<N;i++){
      int cost = dp[i];
      if(cost > X) continue;
      Max(ans, i + calc(V,W,K,Idx,X - cost));
    }

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


Measured memory_bytes: 1280