// ${url}
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

fn dfs(now: usize, graph: &Vec<Vec<usize>>, weight: &mut Vec<i64>) -> i64 {
    for &to in &graph[now] {
        weight[now] += dfs(to, graph, weight);
    }
    weight[now]
}

const INF: i64 = 1e12 as i64;
const LIMIT: usize = 50;

fn take_greedy(mut left_material: i64, items: &Vec<(i64, i64, i64)>) -> i64 {
    let mut created = 0;
    let n = items.len();
    for i in 0..n {
        let can_take = min(items[i].2, left_material / items[i].0);
        left_material -= can_take * items[i].0;
        created += items[i].1 * can_take;
    }
    created
}

fn main() {
    input! {
        n: usize, x: i64, d: i64,
        rootm: i64,
        edges: [(i64, usize1); n-1]
    };

    let mut tree = vec![vec![]; n];
    let mut weight = vec![0; n];
    weight[0] = rootm;
    for i in 0..n-1 {
        tree[edges[i].1].push(i+1);
        weight[i+1] = edges[i].0;
    }
    dfs(0, &tree, &mut weight);
    let mut count = vec![1; n];
    dfs(0, &tree, &mut count);

    let mut items = vec![];
    for i in 0..n {
        items.push((weight[i], count[i], ifv!(i == 0, INF, max(0, d - LIMIT as i64))));
    }
    items.sort_by(|&u, &v| (u.0 * v.1).cmp(&(v.0 * u.1)));

    let count = count.into_iter().map(|x| x as usize).collect::<Vec<_>>();
    let mut total_v = 0;
    for i in 0..n {
        total_v += LIMIT*count[i];
    }
    total_v += 1;
    let mut dp = dvec!(INF; n+1, total_v);
    dp[0][0] = 0;


    for i in 0..n {
        let u = ifv!(i == 0, LIMIT, min(d as usize, LIMIT));
        for ii in 0..u+1 {
            let w = count[i] * ii;
            let v = weight[i] * (ii as i64);
            let ti = i+1;
            for j in 0..total_v {
                let base = dp[i][j];
                if j+w < total_v {
                    dp[ti][j+w] = min(dp[ti][j+w], base+v);
                }
            }
        }
    }

    let mut count = 0;
    for j in 0..total_v {
        let cost = dp[n][j];
        if cost > x {
            continue;
        }
        let left = x-cost;
        count = max(count, j as i64 + take_greedy(left, &items));
    }
    println!("{}", count);
}


Measured memory_bytes: 39164