There are traffic lights and wires. The lights are numbered , and the wires connect them as a tree.
Each light has state or . Every wire must be inspected exactly once, and the inspection order may be chosen freely.
Inspecting a wire with endpoints performs the following actions in order:
Find the minimum total cost paid while inspecting every wire.
The input is given in the following format:
For each test case, print the minimum total cost of inspecting every wire exactly once.
Inspecting the wires in the order pays cost only on wire .
Each case is given in the following format:
is the initial state of light .
No additional constraints. |