#P4211. [LNOI2014] LCA
[LNOI2014] LCA
Description
You are given a rooted tree with nodes (numbered from to ), with root .
The depth of a node is defined as its distance to the root .
Let denote the depth of node , and let denote the lowest common ancestor of and .
There are queries. For each query with given , compute .
Input Format
- The first line contains integers .
- The next lines give parent indices: for each from to , the -th of these lines contains the parent of node .
- The next lines each contain integers .
Output Format
Output lines. Each line contains the answer for one query, taken modulo .
5 2
0
0
1
1
1 4 3
1 4 2
8
5
Hint
Constraints
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号