题号:NC209736
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
Roundgod has a rooted tree with

nodes, and the nodes are indexed from

to

.
Wcy has

quries, in each of which three integers

are given. You need to calculate how many pairs of
)
with
)
whose lowest common ancestor is

.
输入描述:
The first line contains three integers
)
, denoting the number of nodes in the tree nodes, the number of queries, and the index of the root respectively.
Each of the next

lines contains two integers
)
, which means an edge between

and

.
The following

lines contain the descriptions of the queries. Each has three integers
)
.
It is guaranteed that the given edges form a tree.
输出描述:
Print
lines. The
-th line contain single integer for
-th query.
示例1
输入
复制
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