JSOI2015 Salesman (tree DP)

【luogu6082】

 

 Description [title]

T a salesman to a number of small towns to sell commodities, since the area is inaccessible mountains, any possible after all there is only one route between the two towns other towns.

Small T can accurately estimate the net in every town to stay. These net earnings may be negative, that is, sell merchandise profits not worth the cost.

Because of poor roads, small T through every town needs to stay, regardless of the net in the number of places to stay in every town, because many times the cost of meter is not charged, but each town to demand for commodities is also a small T relatively fixed, the residence time after saturated.

In order to strengthen law and order in every town, there are strict rules for the highest number of foreigners stay.

You help design a small T returns the largest tour program, namely from home, stay in each town after finally returned to his hometown of travel program.

Your program just output the maximum benefit, and the optimal solution is unique.

Program does not include details of the route, the same standard program is selected through town and to stay the same. Because the canceled tour is also a scheme, the maximum earnings will not be negative.

T small hometown in net income is zero, because the home is a local, small hometown of T certainly did not limit the number of residence.

 

【Input】

The first input line is a positive integer n (5 <= n <= 100000), indicates the number of towns. Towns named the number 1 to n.

Small hometown named T 1.

The second and third row comprising n-1 integers separated by a space, the i-th row represents the second net i + 1 in the town of residence. The i-th row of the third represents the maximum number of stays of 1 specifies town i +.

All stays are not less than the maximum number of 2.

The next row n-1 to n-1 two integers n for each row x, y, between spaced apart by a space, indicates x, there is a two-way road without other towns between y.

Input data to ensure that all towns are connected. 

 

【Output】

There are two output lines, the first line contains a natural number representing the maximum benefit tour travel.

If the program unique, in the second line of the output "solution is unique", or "not unique solution is" in the second line output.

 

【Sample Input】

  9
  -3 -4 2 4 -2 3 4 6
  4 4 2 2 2 2 2 2
  1 2
  1 3
  1 4
  2 5
  2 6
  3 7
  4 8
  4 9

【Sample Output】

  9

   solution is unique

 

 

Guess you like

Origin www.cnblogs.com/rui-4825/p/12638198.html