#P6782. [Ynoi2008] rplexq
[Ynoi2008] rplexq
Problem Description
Given a rooted tree with nodes, the index of node is .
There are queries. Each query gives . You need to count how many pairs of node indices satisfy , and the lowest common ancestor of and is node .
Input Format
The first line contains three integers , where is the index of the root node.
The next lines each contain two integers , representing an edge.
The next lines each contain three integers , representing a query.
Output Format
Output lines. Each line is the answer to the corresponding query.
10 10 7
4 2
10 4
3 2
6 10
9 2
7 3
1 4
8 2
5 3
8 10 10
2 6 2
3 6 2
4 6 4
3 10 2
8 8 10
3 10 4
2 3 2
2 6 4
1 7 10
0
2
0
1
7
0
2
0
1
0
Hint
Idea: Ynoi, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477.
Constraints: for of the testdata, , .
Sample Explanation
2 6 2: the valid pairs are , .
4 6 4: the valid pair is .
3 10 2: the valid pairs are , , , , , , .
3 10 4: the valid pairs are , .
2 6 4: the valid pair is .
Translated by ChatGPT 5