Minequake
문제
The fully autonomous microbreweries installed in the abandoned Dwarven mines of Moravia are truly a testament to the ingenuinity and craftsmanship of Dwarven engineering! Alas, sometimes earthquakes rattle the mines, leading to misaligned pipes and funnels spilling precious liquid on the floor. As the Exalted Warden of Brewery Safety it is your responsibility to turn off the machines in every hall in case of an earthquake.
Walking through tunnels takes time, so you will inevitably arrive late at many of the machines. This cannot be avoided, but you want to minimise the total amount of spilled liquid.
The Dwarven mines consist of halls connected by tunnels. The entire system is connected, so it is possible to get from any hall to any of the others. It takes unit of time to traverse a tunnel. Switching off a machines and traversing a hall takes no time. In each hall, turning off the machines at time after the earthquake spills liters of liquid. There is exactly one earthquake, the earthquake affects all halls at the same time, and you may not switch off any machines before the earthquake. You can start in any of the halls.
In sample input , the mines look like this:
If you start in hall and visit the rest of the halls in the order , , , , then you can switch off their machines at time (in hall ), time (in hall ), and time (in hall ). This wastes liters of liquid in total. If instead you start in hall and visit the halls in the order , , , the total amount of liquid wasted is liters, which is better.
입력
The first line of input consists of the integer , denoting the number of halls. We assume that the halls are numbered , , . The next lines each contain two space-separated integers and with , meaning that there is a tunnel between hall and hall .
출력
Print a single integer: the minimum amount of spilled liquid, in liters.
예제
예제 1
3 1 2 2 3
3
예제 2
4 1 2 1 3 1 4
7
예제 3
1
0