当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5841:Alice and Bob

题目描述
As you know, Alice and Bob always play game together, and today they get a tree.

The tree consists of $n$ vertices, and vertex $1$ is the root of this tree.

There is a number $w[i]$ written on the ith vectex. Alice and Bob want to play a game on a subtree of this tree. (Note that there are only $n$ subtrees, since the tree is rooted.)

Firstly Alice will choose a vertex in this subtree, and Bob must to choose a different vertex in this subtree. (So, Bob knows which vertex Alice chosen.)

At last they will get a result number equals the XOR sum of the number written on the two vertices which they chosen.

But the problem is that Alice wants the result number to be as maximal as possible while Bob wants the result number to be as minimal as possible, and of course they are clever enough.

Now we are interested in the result number, can you tell us?
输入解释
In the first line there is an integer $T$, indicating the number of test cases.

For each test case:

The first line includes an integer $n$.

The second line includes $n$ integers $w[i]$, indicating the number written on the ith vertex.

For the next $n-1$ lines, each line includes two integers $u$ and $v$, which means an edge in the tree.

The next line includes an integer $m$, which means the number of our queries.

The next $m$ lines, each line includes an integer $u$, indicating Alice and Bob play game on the subtree rooted on the vertex $u$, and we want to know the result number.

$1 \leq n, m \leq 100000, 0 \leq w[i] \leq 100000$.
输出解释
For each test case:

Output “Case #k:”(without quotes) one line first, where k means the case number count from 1.

Then output $m$ lines, each line must include the answer of the corresponding query. If Alice and Bob can’t choose two different vertices, output -1 instead.
输入样例
1
3
1 2 3
1 2
2 3
3	
1
2
3
输出样例
Case #1:
2
1
-1
来自杭电HDUOJ的附加信息
Author UESTC
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5841

最后修改于 2020-10-25T23:26:05+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 131072/131072K(Java/Others)