There is an undirected tree with root $$$1$$$ where each vertex has a weight $$$w_i\in\{1,-1\}$$$.
A volcano at the root erupts at time $$$0$$$. At time $$$t$$$, lava floods all vertices whose distance from the root is at most $$$t$$$, where the distance is the number of edges in the shortest path between the two vertices.
At time $$$0$$$, you are at vertex $$$st$$$ with life value $$$S$$$, initially $$$S=1$$$. Starting at time $$$0$$$ (including time $$$0$$$), the following events happen in order at each time stamp:
Find the maximum number of moves you can make before you die.
Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 10^4$$$). The description of the test cases follows.
For each test case, the first line contains two integers $$$n,st$$$ ($$$2 \le st \le n \le 5\cdot 10^5$$$), denoting the number of vertices and the vertex you start at at time stamp $$$0$$$.
The second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$w_i\in\{1,-1\}$$$,$$$w_{st}=1$$$), where $$$w_i$$$ represents the weight of the vertex $$$i$$$.
The next $$$n-1$$$ lines each contain two integers $$$u,v$$$ ($$$1\le u,v \le n$$$), which describe a pair of vertices connected by an edge.
It is guaranteed that the given graph is a tree and the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
For each test case, output a line with an integer indicating the maximum number of moves you can make.
67 4-1 -1 -1 1 1 1 -12 13 24 35 46 57 68 2-1 1 1 1 1 -1 1 12 16 28 63 87 35 74 58 2-1 1 -1 -1 -1 1 -1 -12 18 24 15 43 47 26 88 41 1 1 1 1 -1 1 -18 13 14 35 46 47 62 58 41 1 1 1 -1 -1 1 12 15 14 58 53 87 26 218 10-1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 1 -1 1 1 1 11 22 33 44 55 66 77 88 99 1010 1111 1212 139 1414 1515 1616 1717 18
6 7 3 3 1 13
Here is a picture that shows the tree in the first test case.
The first test case. One of the optimal sequence of moves is $$$4\to3\to4\to5\to6\to7\to6$$$, which makes $$$6$$$ moves in total. The changes in $$$S$$$ is $$$2\to1\to2\to3\to4\to3\to4$$$. More precisely: