program ARC096F
type data
  integer(4)::w,t
  integer(16)::m
end type

integer(4)::N,X,D
integer(4)::V,W,tmp
integer(4)::ans=0
type(data),allocatable::A(:)
integer(16),allocatable::p(:)
integer(16),allocatable::f(:,:)

read*,N,X,D
allocate(A(N),p(N),f(0:N,0:N**3))
read*,A(1)%m
A(1)%w=1;A(1)%t=10**9
do i=2,N
    read*,A(i)%m,p(i)
    a(i)%w=1;a(i)%t=D
end do
do i=n,2,-1 
    A(p(i))%w=A(p(i))%w+A(i)%w
    A(p(i))%m=A(p(i))%m+A(i)%m
end do
call heapsort(N,A)
f=huge(f)/2
f(0,0)=0
do i=1,N
    do k=0,min(n,a(i)%t)
        do j=0,n**3-k*a(i)%w
            f(i,j+k*a(i)%w)= min(f(i,j+k*a(i)%w),f(i-1,j)+k*a(i)%m)
        end do
    end do
end do

do i=0,n**3
    if(f(n,i)>x)cycle
    W=x-f(n,i);V=i
    do j=1,N
      tmp=min(W/a(j)%m,1*max(0,a(j)%t-n))
      W=W-tmp*a(j)%m
      V=V+tmp*a(j)%w
    end do
    ans=max(ans,V)
end do

print"(I0)",ans
contains
logical function datacmp(A,B)
    type(data)::A,B
    datacmp= (A%w*B%m>A%m*B%w)
end function
subroutine heapsort(n,array)
  implicit none
  integer,intent(in)::n
  type(data),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  type(data):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(datacmp(array(j),array(j+1)))j=j+1
        endif
        if (datacmp(t,array(j)))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end