#include <bits/stdc++.h>

const long long INFLL = 1e18;

using namespace std;

typedef long long ll;

struct item{
    int w;
    long long cost;
    int max_amount;
};

bool comp(item A, item B)
{
    return A.cost * B.w < B.cost * A.w;
}

int main()
{
    int n, x, d;
    cin >> n >> x >> d;
    vector<int> m(n), p(n);
    cin >> m[0];
    p[0] = -1;
    for (int i = 1; i < n; i++)
        cin >> m[i] >> p[i], p[i]--;
    vector<item> items(n);
    for (int i = 0; i < n; i++)
    {
        items[i] = {1, m[i]};
    }
    for (int i = 0; i < n; i++)
    {
        int j = p[i];
        while (j != -1)
        {
            items[j].w++;
            items[j].cost += m[i];
            j = p[j];
        }
    }
    items[0].max_amount = x / items[0].cost + 12;
    for (int i = 1; i < n; i++)
    {
        items[i].max_amount = d;
    }
    vector<item> bag_dp(n);
    for (int i = 0; i < n; i++)
    {
        bag_dp[i] = items[i];
        int am = min(items[i].max_amount, 51);
        bag_dp[i].max_amount = am;
        items[i].max_amount -= am;
    }
    sort(items.begin(), items.end(), comp);
    vector<ll> dp(1);
    for (int i = 0; i < bag_dp.size(); i++)
    {
        for (int j = 0; j < bag_dp[i].max_amount; j++)
        {
            vector<ll> dp2(dp.size() + bag_dp[i].w, INFLL);
            for (int st = dp.size() - 1; st >= 0; st--)
            {
                dp2[st + bag_dp[i].w] = min(dp2[st + bag_dp[i].w], dp[st] + bag_dp[i].cost);
                dp2[st] = min(dp2[st], dp[st]);
            }
            dp = dp2;
        }
    }
    long long ans = 0;
    for (int i = 0; i < dp.size(); i++)
    {
        if (dp[i] > x) continue;
        long long res = i;
        long long coins = x - dp[i];
        for (int j = 0; j < items.size(); j++)
        {
            long long can = min(1ll * items[j].max_amount, coins / items[j].cost);
            res += items[j].w * can;
            coins -= can * items[j].cost;
        }
        //cout << i << " " << dp[i] << " " << coins << " " << res << endl;
        ans = max(ans, res);
    }
    cout << ans;
}
