#P15801. [GESP202603 六级] 完全二叉树
[GESP202603 六级] 完全二叉树
Background
Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1210.
Problem Description
Given a rooted binary tree with nodes, the nodes are numbered in order, and the root node is numbered .
For node , its left child is denoted as , and its right child is denoted as . In particular, if the left child does not exist then , and if the right child does not exist then .
Each node in the tree corresponds to a subtree rooted at that node. Please find, among all subtrees of the given rooted tree, how many of them are complete binary trees.
Input Format
The first line contains a positive integer , representing the number of nodes in the rooted binary tree.
The next lines each contain two positive integers , representing the index of the left child and the index of the right child of node .
Output Format
Output one line containing one integer, representing the number of complete binary trees among all subtrees.
4
2 3
4 0
0 0
0 0
4
4
2 3
0 0
4 0
0 0
3
Hint
For of the test points, is guaranteed.
For all test points, is guaranteed.
Translated by ChatGPT 5