This year, Patrick has decided use his immense power to launch a massive cyberattack on the Canadian Computing Competition's online grader. To set up the attack, he has prepared an ingenious exploit targetted at their servers and is now examining the possible attack vectors.
The CCC Grader's server cluster is organized as a tree with servers (numbered to ) and connections. Server , which manages the grader itself, is designated as the root of the tree. Additionally, Patrick has assigned the servers distinct values which will be used in the attack.
Patrick's exploit is able to target any non-empty subtree in the server cluster and gain control over the entire cluster. However, some subtrees may be easier to exploit than others. The easiness score of a subtree is defined according to the following rules:
- A set is said to be good if it is closed under the bitwise exclusive or operation. In other words, it is good if, for all , is also in . Note that it's possible that .
- For a given subtree, we define a set which contains all of the values present in the subtree.
- If is good, the easiness of the subtree is . Otherwise, the easiness of the subtree is defined as the minimum number of elements that must be added to to make it good.
Since Patrick has been procrastinating as usual, he is simply going to choose a random non-empty subtree to use the exploit on. He would like you to help him find out the average easiness score of all possible subtree choices, rounded down to the nearest integer.
Constraints
In all subtasks,
Subtask 1 [20%]
For all , is for some .
Subtask 2 [80%]
No further constraints.
Input Specification
The first line will contain two space-separated integers, .
The next line will contain space-separated integers, .
The next will each contain two space-separated integers, and , meaning that there's a connection between servers and .
Output Specification
Output the average easiness of all subtrees, rounded down to the nearest integer.
Sample Input
5
1 2 3 4 5
1 2
1 3
2 4
2 5
Sample Output
2
Sample Explanation
The value is added to the sets of the subtrees rooted at , , and to form good sets of , , . Therefore, the easiness scores of these subtrees are all .
Values of , , , , and are added to the set of the subtree rooted at to form a good set of , for an easiness score of .
Values of , , and are added to the subtree rooted at to form the same good set as the one rooted at , for an easiness score of .
The average value is then .
Note that the set is good because for any two elements, their exclusive or is also in the set. For example, which is in the set. is also in the set.
Comments