#include <bits/stdc++.h>
    using namespace std;
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    #define inf 1000000005
    #define all(a) (a).begin(), (a).end()
    #define ms(a,x) memset(a, x, sizeof(a))
    #define mod 1000000007
    #define sz(a) ((int)(a).size())
     
    template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
    template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
    template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
    template<class T> int cntbit(T s) { return __builtin_popcount(s);}
    #define Rep(i,n) for(int i = 0; i < (n); ++i)
    #define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
    #define For(i,a,b) for(int i = (a); i <= (b); ++i)
    #define Ford(i,a,b) for(int i = (a); i >= (b); --i)
     
    typedef unsigned long long ull;
    typedef long long ll;
    typedef long double ld;
    #define eps 1e-9
    typedef pair<int, int> II;
    template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
    template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
    #define PI 2 * acos(0)
     
    #define maxn 52
     
    struct Sep{
      ll num, sum, limit;
      Sep(){};
      Sep(ll _num, ll _sum, ll _limit){
        sum = _sum;
        num = _num;
        limit = _limit;
      }
      bool operator < (const Sep &S)const{
        return (ld)(sum) / (ld)(num) < (ld)(S.sum) / (ld)(S.num);
      }
    };
     
    int n;
    ll x, d;
    ll a[maxn], c[maxn], D[maxn], F[maxn];
    vector<int> V[maxn];
    Sep A[maxn];
    ll f[5505];
    ll g[5505];
    int add = 2505;
     
    void go(int u){
      D[u] = 1; F[u] = a[u];
      Rep(i, sz(V[u])){
        int v = V[u][i];
        go(v);
        D[u] += D[v];
        F[u] += F[v];
      }
    }
     
    int main(){
        srand(1412);
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    	  /* freopen("in.txt", "r", stdin); */
        cin >> n >> x >> d;
        For(i, 1, n){
          cin >> a[i];
          if(i > 1){
            int u;
            cin >> u;
            V[u].pb(i);
          }
        }
     
        go(1);
        For(i, 1, n){
          ll num = d * D[i];
          if(i == 1) num = inf;
          A[i] = Sep(D[i], F[i], num);
        }
     
        sort(A + 1, A + n + 1);
        
        ll res = 0;
        For(i, 1, n){
          ll X = (x / A[i].sum) * A[i].num;
     
          /* cout << i << " " << A[i].num << " " << A[i].sum << " " << A[i].limit << " " << X << endl; */
     
          if(X <= A[i].limit){
            x -= X / A[i].num * A[i].sum;
            c[i] = X;
          } else{
            c[i] = (A[i].limit / A[i].num) * A[i].num;
            x -= c[i] / A[i].num * A[i].sum;
          }
          res += c[i];
          /* cout << c[i] << " " << x << endl; */
        }
     
        ms(f, 0x3f);
        f[add] = 0;
        
        for(int t = 1; t <= n; t++){
          Rep(i, 5505){
            g[i] = f[i];
            f[i] = (ll)((1ll << 60) * 1.3);
          }
          for(int i = 0; i < 5100; i++) if(g[i] < (1ll << 60)){
            for(int j = -50; j <= 50; j++) {
              ll X = i + j * A[t].num;
              ll gt = g[i] + j * A[t].sum;
              ll newc = c[t] + j * A[t].num;
              if(X < 0 || X >= 5100 || newc < 0 || newc > A[t].limit){
                continue;
              }
              f[X] = min(f[X], gt);
            }
          }
        }
        for(int i = 5100; i >= add; i--) if(f[i] <= x){
          cout << res + i - add << endl;
          return 0;
        }
     
        return 0;
    }

Measured memory_bytes: 384