#P2633. Count on a tree
Count on a tree
Description
Given a tree with nodes, each node has a weight. There are queries. For each query, you are given , and you need to answer the -th smallest node weight on the path between and .
Here, is the answer to the previous query, initially defined as , i.e., in the first query, is not xored.
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer denotes the weight of node .
Each of the next lines contains two integers , indicating that there is an edge between node and node .
Each of the last lines contains three integers , representing one query.
Output Format
Output lines, each containing a positive integer, which is the answer to each query.
8 5
105 2 9 3 8 5 7 7
1 2
1 3
1 4
3 5
3 6
3 7
4 8
2 5 1
0 5 2
10 5 3
11 5 4
110 8 2
2
8
9
105
7
Hint
Constraints:
For of the testdata, , and node weights are in .
Please refrain from brute force...
Source: bzoj2588 Spoj10628.
The testdata for this problem is self-made by Luogu, generated using CYaRon in 5 minutes.
Translated by ChatGPT 5
京公网安备 11011102002149号