#P5384. [Cnoi2019] 雪松果树
[Cnoi2019] 雪松果树
Description
The cedar cone tree is a tree with nodes rooted at .
In addition, Cirno has queries. Each query is an ordered pair , asking how many -cousins node has.
We define:
The 1-father of node is the node on the path (excluding ) that is closest to .
The -father of node is the 1-father of the node “the -father of ”.
The -son of node is the set of all nodes whose -father is .
The -cousin of node is the -son of the node “the -father of ” (excluding itself).
Input Format
The first line contains two integers and .
The second line contains integers. The -th integer denotes the 1-father of node .
The following lines each contain an ordered pair .
Output Format
Output one line with numbers, where each number is the answer to a query. If does not have a -father, output .
5 2
1 2 1 4
2 1
3 2
1 1
Hint
Constraints: |Test Point ID|||Special Property| |----|----|----|-----| |1,2|||| |3,4|||| |5,6|||| |7|||| |8,9,10|||| |11,12,13,14|||The tree is generated randomly| |15,16,17,18,19,20||||
In addition, there is a set of hack testdata worth points.
Translated by ChatGPT 5
京公网安备 11011102002149号