#ARC096D. [ARC096F] Sweet Alchemy

[ARC096F] Sweet Alchemy

Score : 900900 points

Problem Statement

Akaki, a patissier, can make NN kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 11, Doughnut 22, ...,..., Doughnut NN. In order to make one Doughnut ii (1iN)(1 \leq i \leq N), she needs to consume mim_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.50.5 doughnuts.

The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 11. Specifically, the recipe of Doughnut ii (2iN)(2 \leq i \leq N) is a direct modification of the recipe of Doughnut pip_i (1pi<i)(1 \leq p_i < i).

Now, she has XX grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:

  • Let cic_i be the number of Doughnut ii (1iN)(1 \leq i \leq N) that she makes. For each integer ii such that 2iN2 \leq i \leq N, cpicicpi+Dc_{p_i} \leq c_i \leq c_{p_i} + D must hold. Here, DD is a predetermined value.

At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.

Constraints

  • 2N502 \leq N \leq 50
  • 1X1091 \leq X \leq 10^9
  • 0D1090 \leq D \leq 10^9
  • 1mi1091 \leq m_i \leq 10^9 (1iN)(1 \leq i \leq N)
  • 1pi<i1 \leq p_i < i (2iN)(2 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN XX DD

m1m_1

m2m_2 p2p_2

::

mNm_N pNp_N

Output

Print the maximum number of doughnuts that can be made under the condition.

3 100 1
15
10 1
20 1
7

She has 100100 grams of Moto, can make three kinds of doughnuts, and the conditions that must hold are c1c2c1+1c_1 \leq c_2 \leq c_1 + 1 and c1c3c1+1c_1 \leq c_3 \leq c_1 + 1. It is optimal to make two Doughnuts 11, three Doughnuts 22 and two Doughnuts 33.

3 100 10
15
10 1
20 1
10

The amount of Moto and the recipes of the doughnuts are not changed from Sample Input 1, but the last conditions are relaxed. In this case, it is optimal to make just ten Doughnuts 22. As seen here, she does not necessarily need to make all kinds of doughnuts.

5 1000000000 1000000
123
159 1
111 1
135 3
147 3
7496296