Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)
E1
The Game (Easy Version)
Codeforces
2000
原题
← DE2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, you only need to find one of the possible nodes Cirno may choose. You can hack only if you solved all versions of this problem.

翻译中…

Cirno and Daiyousei are playing a game with a tree$^{\text{∗}}$ of $n$ nodes, rooted at node $1$. The value of the $i$-th node is $w_i$. They take turns to play the game; Cirno goes first.

翻译中…

In each turn, assuming the opponent chooses $j$ in the last turn, the player can choose any remaining node $i$ satisfying $w_i \gt w_j$ and delete the subtree$^{\text{†}}$ of node $i$. In particular, Cirno can choose any node and delete its subtree in the first turn.

翻译中…

The first player who can not operate wins, and they all hope to win. Find one of the possible nodes Cirno may choose so that she wins if both of them play optimally.

翻译中…

$^{\text{∗}}$A tree is a connected graph without cycles. $^{\text{†}}$Node $u$ is considered in the subtree of node $i$ if any path from $1$ to $u$ must go through $i$.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ ($1 \leq t \leq 10^5$) — the number of input test cases.

翻译中…

The first line of each test case contains one integer $n$ ($1 \le n \le 4\cdot 10^5$) — the number of nodes in the tree.

翻译中…

The second line contains $n$ integers $w_1,w_2,\ldots,w_n$ ($1 \le w_i \le n$) — the value of each node.

翻译中…

The next $n-1$ lines contain the edges of the tree. The $i$-th line contains two integers $u_i,v_i$ ($1\le u_i,v_i \le n$, $u_i \neq v_i$) — an edge connecting $u_i$ and $v_i$. It is guaranteed that the given edges form a tree.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $4\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, print one line.

翻译中…

If Cirno wins the game, print any possible node she may choose in the first turn.

翻译中…

Otherwise, print "0" (without quotes).

翻译中…

Note

翻译中…

In the first test case:

翻译中…
  1. If Cirno chooses $1$ or $3$ in the first turn, Daiyousei cannot make a move, so Daiyousei wins.
  2. If Cirno chooses $2$ or $4$ in the first turn, Daiyousei can only choose $3$, but after it Cirno cannot make a move, so Cirno wins.
翻译中…

Therefore, all possible nodes Cirno may choose are $2$ and $4$.

翻译中…

In the second test case, regardless of which node Cirno chooses, Daiyousei cannot make a move, so Daiyousei wins.

翻译中…

In the third and fourth test case, the only possible node Cirno may choose in the first turn is $2$.

翻译中…

In the fifth test case, all possible nodes Cirno may choose in the first turn are $3,4,6,7$ and $10$.

翻译中…

样例

Input #1
5
4
2 2 4 3
1 2
1 3
2 4
5
1 2 3 4 5
1 2
2 3
3 4
4 5
3
1 2 3
1 2
1 3
5
3 1 3 4 5
1 2
2 3
3 4
4 5
10
1 2 3 2 4 3 3 4 4 3
1 4
4 6
7 4
6 9
6 5
7 8
1 2
2 3
2 10
Output #1
2
0
2
2
10
InputCopy OutputCopy
题目信息
题号
2062E1
时间限制
4 s
内存限制
512 MB
标签
数据结构
DFS 及类似
博弈论
图论
贪心
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。