| Soy Cup #2: Vivian |
|---|
| Finished |
Kagari is managing a finished world tree. The tree is rooted at a specific vertex $$$r$$$, and each vertex has an integer value. To process the tree more efficiently, she may do the following operation on an arbitrary vertex $$$v$$$ ($$$v \neq r$$$):
During this process, Kagari may also query the $$$k$$$-MEX$$$^{\text{∗}}$$$ value of the set of vertex integer values in a given subtree$$$^{\text{†}}$$$. Can you help her program to answer her queries efficiently?
$$$^{\text{∗}}$$$The $$$k$$$-th minimum excluded ($$$k$$$-MEX) of a collection of integers $$$c_1, c_2, \ldots, c_n$$$ is defined as the $$$k$$$-th smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
$$$^{\text{†}}$$$A vertex $$$u$$$ is said to be in the subtree of vertex $$$v$$$ if and only if the path from $$$u$$$ to the root contains $$$v$$$.
The first line of each test contains three integers $$$n$$$, $$$q$$$, and $$$r$$$ ($$$1 \le n, q \le 10^6$$$, $$$1 \le r \le n$$$) — the size of the tree, the number of queries and operations, and the root vertex.
The second line of each test contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$0\le a_i\le n$$$) — the integer values of each vertex.
The following $$$n-1$$$ lines of each test describe the tree. Each of the lines contains two integers $$$u$$$ and $$$v$$$ that indicate an edge between vertex $$$u$$$ and $$$v$$$. It is guaranteed that these edges form a tree.
The following $$$q$$$ lines of each test describe the queries and operations. Each of the lines is either of:
For each $$$k$$$-MEX query, output an integer — the answer to that query.
11 6 14 5 6 0 2 1 8 2 3 0 41 21 32 43 53 85 65 77 97 105 112 3 11 72 5 32 4 21 92 1 2
5 5 2 9
The initial tree is shown in the figure below.
In the first query, the values of the subtree of vertex $$$3$$$ are $$$[6,2,1,8,2,3,0,4]$$$, and its $$$1$$$-MEX is $$$5$$$.
After the operation on vertex $$$7$$$, the tree is shown in the figure below.
In the second query, the values of the subtree of vertex $$$5$$$ are $$$[2,1,4]$$$, and its $$$3$$$-MEX is $$$5$$$.
In the third query, the values of the subtree of vertex $$$4$$$ are $$$[0]$$$, and its $$$2$$$-MEX is $$$2$$$.
After the operation on vertex $$$9$$$, the tree is shown in the figure below.
In the fourth query, the values of the subtree of vertex $$$1$$$ are $$$[4,5,6,0,2,1,8,2,3,0,4]$$$, and its $$$2$$$-MEX is $$$9$$$.
| Name |
|---|


