CF840E.In a Trap

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Lech got into a tree consisting of nn vertices with a root in vertex number 11 . At each vertex ii written integer aia_{i} . He will not get out until he answers qq queries of the form uu vv . Answer for the query is maximal value among all vertices ii on path from uu to vv including uu and vv , where dist(i,v)dist(i,v) is number of edges on path from ii to vv . Also guaranteed that vertex uu is ancestor of vertex vv . Leha's tastes are very singular: he believes that vertex is ancestor of itself.

Help Leha to get out.

The expression means the bitwise exclusive OR to the numbers xx and yy .

Note that vertex uu is ancestor of vertex vv if vertex uu lies on the path from root to the vertex vv .

输入格式

First line of input data contains two integers nn and qq ( 1<=n<=51041<=n<=5·10^{4} , 1<=q<=1500001<=q<=150000 ) — number of vertices in the tree and number of queries respectively.

Next line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 0<=ai<=n0<=a_{i}<=n ) — numbers on vertices.

Each of next n1n-1 lines contains two integers uu and vv ( 1<=u,v<=n1<=u,v<=n ) — description of the edges in tree.

Guaranteed that given graph is a tree.

Each of next qq lines contains two integers uu and vv ( 1<=u,v<=n1<=u,v<=n ) — description of queries. Guaranteed that vertex uu is ancestor of vertex vv .

输出格式

Output qq lines — answers for a queries.

输入输出样例

  • 输入#1

    5 3
    0 3 2 1 4
    1 2
    2 3
    3 4
    3 5
    1 4
    1 5
    2 4
    

    输出#1

    3
    4
    3
    
  • 输入#2

    5 4
    1 2 3 4 5
    1 2
    2 3
    3 4
    4 5
    1 5
    2 5
    1 4
    3 3
    

    输出#2

    5
    5
    4
    3
    
首页