Sweet, sour, bitter, salty

Cut edges of a rooted binary tree so that at least X resulting components each contain at least K nodes, minimizing total cut cost.

Medium5TreeDynamic programmingDFSGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

A human body needs a way to tell safe food from dangerous food. The human tongue detects four kinds of taste: sweet, sour, bitter, and salty. What people call tasty or not tasty comes from the combination of these four tastes and personal preference.

Junpyo cannot taste anything. Seohyun noticed it when Junpyo ate sour kimchi and said it was not sour, and she worried that he would get hurt because he cannot detect dangerous tastes. She started looking into why Junpyo cannot taste, and why he will not admit that his sense of taste is abnormal, and she found that he has NN taste buds numbered 1 to NN.

Junpyo's taste buds are connected to each other and form a single binary tree rooted at bud 1. One connected clump of buds is one bud group. An ordinary person has at least XX bud groups. Taste is a combined sensation, so a bud group works properly only when it holds at least KK buds. Seohyun wants to cut connections between buds so that Junpyo, like an ordinary person, ends up with at least XX bud groups holding at least KK buds each. Bud groups with fewer than KK buds may remain. They simply do not count.

Every time a connection is cut, the rest of Junpyo's nervous system takes damage equal to the strength of that connection. If the connection between bud A and bud B affects each of them by 10, cutting it gives Junpyo 10 pain. Junpyo would live an even harder life if his other senses were hurt while his taste came back, so Seohyun wants to minimize the sum of the strengths of the connections she cuts, that is, the total pain Junpyo takes. Find the minimum total pain Junpyo must take to taste again.

Input

The first line contains the number of taste buds Junpyo has, NN (1 ≤ NN ≤ 5,000), the minimum number of buds one bud group needs to work properly, KK (1 ≤ KK ≤ 100), and the minimum number of working bud groups needed to taste like an ordinary person, XX (1 ≤ XX ≤ 100).

Each of the next N1N-1 lines contains the information of bud ii (2 ≤ iiNN), namely PiP_i (1 ≤ PiP_iNN) and CiC_i (0 ≤ CiC_i ≤ 100,000). The parent of bud ii is bud PiP_i, and cutting the connection between the two causes CiC_i pain. Bud 1 is the root, so no line is given for it.

Output

Print the minimum total pain Junpyo must go through to taste again. If there is no way for him to get his sense of taste back, print -1.

Hint

In the second example, cutting the connection between bud 2 and bud 4 gives the smallest total pain.