National Olympiad in Informatics, China, 2011
On planet W, there exist
Constructing each road will require a cost. This cost is equal to the
length of the road multiplied by the absolute difference of the number
of countries on each side of the road. For example, the road represented
by a dashed line in the figure below has, respectively,
Since both the number of countries and the number of ways to construct the roads are extremely large, as well the construction costs for each way is hard to calculate by humans, the kings have decided to hire a person to design a software to do this. This piece of software should be able to calculate the total cost of constructing all the roads, given a way to construct them. Please help the kings to write such a program.
Input Specification
The first line will contain an integer
For the following
Output Specification
Output a single integer, the total cost of constructing all the roads.
Sample Input
6
1 2 1
1 3 1
1 4 2
6 3 1
5 2 1
Sample Output
20
Constraints
The attributes of all the test cases are outlined below.
Test Case | Size of (Note the | Constraints |
---|---|---|
Problem translated to English by .
Comments