#P10795. 『SpOI - R1』Lamborghini (Demo)
『SpOI - R1』Lamborghini (Demo)
Problem Description
You are given an unrooted tree. Each node has two attributes .
Define for the directed path as follows:
- If the node with the smallest on the path is , and , then .
- Otherwise, .
Compute .
Input Format
The first line contains an integer .
The second line contains integers separated by spaces; the -th integer denotes of node .
The third line contains integers separated by spaces; the -th integer denotes of node .
The next lines each contain two integers , describing an edge in the tree.
Output Format
Output one line with one integer, the answer.
3
1 2 3
1 3 5
1 2
2 3
10
5
1 3 5 8 10
1 5 3 2 8
2 1
3 1
4 1
5 3
22
Hint
Sample #1 Explanation
- .
- .
- .
- .
- .
- .
- .
- .
- .
Therefore, .
Constraints
This problem enables subtask bundling and subtask dependencies.
For of the data, all are pairwise distinct, , and .
| Subtask | Special Property | Score | Dependencies | ||
|---|---|---|---|---|---|
| 1 | None | None | |||
| 2 | 1 | ||||
| 3 | None | ||||
| 4 | |||||
| 5 | None | 1,2,3,4 |
Special property : Node is fixed as the root of the tree. For any pair of nodes with , if is an ancestor of , then .
Special property : .
Translated by ChatGPT 5