QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#15066. salesman

统计

A salesman, Little T, needs to travel to several towns to promote products. Because the region is a mountainous area with poor transportation, there is a unique path between any two towns that does not pass through other towns. Little T can accurately estimate the net profit of staying in each town. These net profits may be negative, meaning the profit from promoting products does not cover the expenses. Due to the poor transportation, Little T must stay in every town he passes through. The number of stays in each town is independent of the net profit at that location, as many costs are not charged per visit, and the demand for Little T's products in each town is relatively fixed; it becomes saturated after one stay. To strengthen security, each town has strict regulations on the maximum number of stays for outsiders. Please help Little T design a tour plan with maximum profit, starting from his hometown, staying in every town he passes through, and finally returning to his hometown. Your program only needs to output the maximum profit and whether the optimal plan is unique. The plan does not include the details of the route; the criterion for the same plan is whether the set of towns visited and stayed in is the same. Since canceling the tour is also a plan, the maximum profit will not be negative. Little T's net profit in his hometown is zero because he is a local, and naturally, there is no limit on the number of stays in his hometown.

Input

The first line of the input is a positive integer $n$, representing the number of towns. The towns are named from $1$ to $n$. Little T's hometown is named $1$. The second and third lines both contain $n-1$ space-separated integers. The $i$-th number in the second line represents the net profit of staying in town $i+1$. The $i$-th number in the third line represents the maximum number of stays allowed in town $i+1$. All maximum stay limits are no less than $2$. The following $n-1$ lines each contain two positive integers $x$ and $y$ between $1$ and $n$, separated by a space, indicating that there is a bidirectional road between $x$ and $y$ that does not pass through other towns. The input data guarantees that all towns are connected.

Output

The output consists of two lines. The first line contains a natural number representing the maximum profit of the tour. If the plan is unique, output "solution is unique" on the second line; otherwise, output "solution is not unique".

Examples

Input 1

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

Output 1

9
solution is unique

Note 1

The optimal route includes towns $1, 2, 4, 5, 9$.

Constraints

All net profits are between $-500$ and $500$, and all maximum stay limits are no greater than $1000$.

  • $30\%$ of the data satisfies: $5 \le n \le 10$
  • $60\%$ of the data satisfies: $5 \le n \le 1000$
  • $100\%$ of the data satisfies: $5 \le n \le 100000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.