You are given a tree rooted at $$$1$$$ with $$$n$$$ vertices and a permutation $$$p$$$ of length $$$n$$$ consisting of integers $$$0, 1, \ldots, n - 1$$$, where $$$p_v$$$ represents the weight of vertex $$$v$$$.
Let $$$S_v$$$ denote the set of weights written on the vertices belonging to the path from $$$1$$$ to $$$v$$$. Define a function $$$f$$$ as $$$f(v) = \mathrm{MEX}(S_v)$$$, that is, the $$$\mathrm{MEX}$$$ over the set consisting of the weights of vertices on the simple path between the root and $$$v$$$ (inclusive), where $$$\operatorname{MEX}$$$ of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
Also, given the following operation:
Your goal is to find the maximum value of $$$\sum\limits_{v = 1}^n f(v)$$$ after performing the above operation no more than once (possibly zero).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of vertices of the tree.
The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$ ($$$0 \le p_i \le n - 1$$$) — the elements of array $$$p$$$. It is guaranteed that every integer from $$$0$$$ to $$$n - 1$$$ appears exactly once in $$$p$$$.
Then $$$n - 1$$$ lines follow, each line contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$), indicating an edge between vertices $$$x_i$$$ and $$$y_i$$$. It is guaranteed that these edges form a tree.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single line containing an integer: the maximum value of $$$\sum\limits_{v = 1}^n f(v)$$$ after performing the above operation no more than once (possibly zero).
71031 0 21 21 361 4 5 2 0 31 41 56 22 52 351 2 3 0 41 22 33 44 5109 8 7 1 3 2 5 4 6 06 103 18 74 22 87 510 93 96 498 4 0 6 5 7 3 1 28 34 24 69 37 61 58 59 271 5 2 3 6 0 47 64 37 25 12 46 5
14129302617
In the first example, not doing any operation is optimal, so the answer is $$$1$$$.
In the second example, we have
And we have the following options:
So the answer is $$$4$$$, by doing operation on vertex $$$3$$$.