#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 sum * S.num < S.sum * num;
  }
};

int n;
ll x, d;
ll a[maxn], c[maxn], D[maxn], F[maxn];
vector<int> V[maxn];
Sep A[maxn];
ll f[255005];
ll g[255005];
int add = 125005;

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;
    ll temp = x;
    For(i, 1, n){
      ll X = (temp / A[i].sum) * A[i].num;
      /* cout << i << " " << A[i].num << " " << A[i].sum << " " << temp << " " << limit; */
      if(X <= A[i].limit){
        temp -= X / A[i].num * A[i].sum;
        c[i] = X;
      } else{
        c[i] = (A[i].limit / A[i].num) * A[i].num;
        temp -= c[i] / A[i].num * A[i].sum;
      }
      res += c[i];
      /* cout << c[i] << " " << x << endl; */
    }

    ms(f, 0x3f);
    f[add] = 0;
    /* cout << res << endl; */
    
    for(int t = 1; t <= n; t++){
      Rep(i, 255005){
        g[i] = f[i];
        f[i] = (ll)((1ll << 60) * 1.3);
      }
      for(int i = 0; i < 251000; i++) if(g[i] < (1ll << 60)){
        ll have = (x - g[i]);
        ll Max = min(A[t].limit / A[t].num, have / A[t].sum);
        for(int j = -50; j <= 0; j++) {
          ll X = i + (j + Max) * A[t].num - c[t];
          ll gt = g[i] + (j + Max) * A[t].sum;
          ll newc = Max + j;
          if(X < 0 || X >= 251000 || newc < 0 || newc > A[t].limit / A[t].num){
            continue;
          }
          f[X] = min(f[X], gt);
        }
      }
    }

    for(int i = 251000; i >= add; i--) if(f[i] <= x){
      cout << res + i - add << endl;
      return 0;
    }

    return 0;
}

Measured memory_bytes: 4224