#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mem(a) memset(a,0,sizeof(a))

typedef long long ll;
typedef pair<int,int> pii;

const int mn=55;

int n;
ll m,D;
int a[mn];
vector<int> g[mn];
struct item{
	ll v,w,num;//value weight
	bool operator < (const item &e) const{
		return v*e.w>e.v*w;
	}
}p[mn];
void dfs(int v,int x){
	p[x].w+=a[v];
	p[x].v++;
	for(int &i:g[v]){
		dfs(i,x);
	}
}

ll d[mn*mn*mn];

inline ll greedy(ll m){
	ll ans=0;
	for (int i = 1; i <= n; i++) {
		ll u = min(m / p[i].w,p[i].num);
		m -= u * p[i].w, ans += p[i].v * u;
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin >> n >> m >> D;
	cin >> a[1];
	for (int i = 2; i <= n; i++) {
		int u;
		cin >> a[i] >> u;
		g[u].pb(i);
		p[i].num = max(D - 50,0ll);
	}
	p[1].num = 1e9;
	for (int i = 1; i <= n; i++) dfs(i, i);
	sort(p + 1, p + n + 1);
	int maxpos = 0;
	fill_n(d, mn*mn*mn, 1ll << 58);
	d[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int k = 1; k <= min(50ll, D); k++) {
			maxpos += p[i].v;
			for (int j = maxpos; j >= p[i].v; j--) {
				d[j] = min(d[j], d[j - p[i].v] + p[i].w);
			}
		}
	}
	ll ans=0;
	for (int i = 0; i <= maxpos; i++) {
		if (d[i] <= m) ans=max(ans,greedy(m-d[i])+i);
	}
	cout << ans;
	return 0;
}