#abc321e. E - Complete Binary Tree
E - Complete Binary Tree
Score : points
问题描述
存在一棵包含 个顶点的树,顶点编号为 到 。对于每个 ,存在一条边连接顶点 和顶点 。除此之外没有其他边。
在该树中,找出距离顶点 距离为 的顶点数量。这里,两个顶点 和 之间的距离定义为连接顶点 和顶点 的简单路径上的边数。
你需要解决 个测试用例。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a tree with vertices numbered to . For each , there is an edge connecting vertex and vertex . There are no other edges.
In this tree, find the number of vertices whose distance from vertex is . Here, the distance between two vertices and is defined as the number of edges in the simple path connecting vertices and .
You have test cases to solve.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format, where represents the -th test case:
Each test case is given in the following format:
Output
Print lines.
The -th line should contain the answer to the -th test case as an integer.
Sample Input 1
5
10 2 0
10 2 1
10 2 2
10 2 3
10 2 4
Sample Output 1
1
3
4
2
0
The tree for is shown in the following figure.
Here,
- There is vertex, , whose distance from vertex is .
- There are vertices, , whose distance from vertex is .
- There are vertices, , whose distance from vertex is .
- There are vertices, , whose distance from vertex is .
- There are no vertices whose distance from vertex is .
Sample Input 2
10
822981260158260522 52 20
760713016476190629 2314654 57
1312150450968417 1132551176249851 7
1000000000000000000 1083770654 79
234122432773361868 170290518806790 23
536187734191890310 61862 14
594688604155374934 53288633578 39
1000000000000000000 120160810 78
89013034180999835 14853481725739 94
463213054346948152 825589 73
Sample Output 2
1556480
140703128616960
8
17732923532771328
65536
24576
2147483640
33776997205278720
7881299347898368
27021597764222976
update @ 2024/3/10 01:40:52