#P3408. Minimum Payment for Approval

    ID: 16663 Type: Default 1000ms 256MiB

Minimum Payment for Approval

Minimum Payment for Approval

Little A is deeply in love with Little B. However, Little B is too strong compared to Little A and would never accept her proposal without conditions. Little B sets a condition based on her subordinates organized in a tree structure:

  • There are n subordinates (numbered 1 through n), with Little B herself designated as node 0 at the top.
  • For each person i (1 ≤ i ≤ n):
    • If person i has no subordinate, Little A can pay him Ai dollars to have him send a letter to his direct superior indicating Little A's love.
    • If person i has subordinates, he will send a letter if the proportion of his direct subordinates who send letters is no less than \(\dfrac{A_i}{T}\). Note that no payment is given directly to non‐leaf nodes.
  • Finally, Little B (node 0) will accept Little A's proposal if the proportion of her direct subordinates who send letters is at least \(\dfrac{C}{T}\).

Your task is to determine the minimum total amount Little A has to pay to ensure that Little B accepts her proposal.

Note: For each non‐leaf node i (i.e. person with direct subordinates), the condition is met if at least \(\lceil\frac{A_i\cdot d}{T}\rceil</em> of its d direct subordinates send letters. Similarly, for Little B (node 0 with d direct subordinates), at least \(\lceil\frac{C\cdot d}{T}\rceil</em> letters are required.

inputFormat

The input begins with a line containing three integers: n, T, and C (separated by spaces), where n is the number of persons (excluding Little B). Then follow n lines. The i-th of these lines (for i = 1 to n) contains two integers p and Ai (separated by space) indicating that person i's direct superior is person p (with 0 representing Little B) and his associated parameter (or cost, if he is a leaf) is Ai.

outputFormat

Output a single integer: the minimum total amount Little A must pay so that Little B accepts her proposal. If it is impossible to satisfy the condition, output -1.

sample

3 10 5
0 2
0 8
1 1
1

</p>