#P3408. 恋爱

恋爱

Description

Xiao A fell in love with Xiao B!!! However, Xiao A is too weak compared to Xiao B, so she would certainly not agree to Xiao A’s request. After Xiao A’s persistent pursuit, Xiao B set the following conditions:

  • Xiao B has nn subordinates (excluding Xiao B) forming a tree structure. Xiao B is at the top, and everyone else has exactly one direct superior.
  • Xiao B is numbered 00, and others are numbered 1n1 \sim n.
  • For the ii-th person: if this person has no subordinates, then Xiao A can give them AiA_i yuan, after which they will write a letter to their direct superior, stating that Xiao A is confessing to Xiao B.
  • If at least a proportion of AiT\dfrac{A_i}{T} among their direct subordinates write letters stating that Xiao A is confessing to Xiao B, then they will also write a letter to their direct superior.
  • If at least a proportion of CT\dfrac{C}{T} among Xiao B’s direct subordinates write letters stating that Xiao A is confessing to Xiao B, then she will agree to Xiao A’s request.

Please determine the minimal total amount of money Xiao A needs to pay to make Xiao B accept Xiao A’s confession.

Input Format

The first line contains three integers n,T,Cn, T, C.

Then follow nn lines. The ii-th line contains two integers Bi,AiB_i, A_i, where BiB_i is the direct superior of ii, and it is guaranteed that Bi<iB_i < i.

Output Format

Output the minimal total amount of money needed.

14 5 3
0 3
0 3
1 10
1 10
2 3
2 10
2 3
5 10
7 10
5 10
7 10
5 10
7 10
5 10

50

Hint

  • For 20%20\% of the testdata, the number of people without direct subordinates 15\le 15.
  • For 40%40\% of the testdata, n2000n \le 2000.
  • Additionally, for 10%10\% of the testdata, Bi=0B_i = 0.
  • Additionally, for 10%10\% of the testdata, C=1C = 1 and for people with direct subordinates T/Ai>nT / A_i > n.
  • Additionally, for 10%10\% of the testdata, Bi=i1B_i = i - 1.
  • For 100%100\% of the testdata, 1n5000001 \le n \le 500000, 1T1091 \le T \le {10}^9, Bi<iB_i < i, 1AiT1 \le A_i \le T.

Translated by ChatGPT 5