Statement
Dadas manages a project that depends on many packages. The dependency structure is given as a tree rooted at vertex . Vertex represents the project itself, and every other vertex represents a package.
Some packages may have security vulnerabilities. You may perform the following two operations.
- Normal patch: Patch a vulnerable package . This costs and fixes only the vulnerability at .
--forcepatch: Force-update package . This costs and fixes every vulnerability at and all descendants of . This operation may be performed even if itself is not vulnerable.
The affected vertices of every operation are determined by the original tree. Operations do not change the tree structure or any cost, create new vulnerabilities, or restore vulnerabilities that have already been fixed.
At most --force patches may be performed. There is no limit on the number of normal patches. No operation may be performed on vertex .
Find the minimum total cost required to fix all vulnerabilities.
Input
The input is given from Standard Input in the following format:
Output
For each test case, print the minimum total cost required to fix all vulnerabilities on one line.
Constraints
- .
- .
- .
Subtasks
Samples
In the first test case, applying --force to package fixes the vulnerabilities at packages and for cost . Applying --force to package costs another , for a total cost of .