#K8566. Super Full Binary Tree
Super Full Binary Tree
Super Full Binary Tree
In this problem, you are given a tree defined by a series of node descriptions. A tree is called a super full binary tree if and only if:
- The tree is non-empty and all leaves reside at the same depth.
- Every non-leaf node has exactly three children.
The input will start with an integer representing the number of nodes (each node is described exactly once). Each of the subsequent lines corresponds to one node. A node description is given as follows:
- If the node is a leaf, the line contains:
node -1
. - If the node is not a leaf, the line contains:
node child1 child2 child3
.
The tree is rooted at node 1. Your task is to determine whether the given tree is a super full binary tree.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer N representing the number of nodes (or node descriptions) in the tree.
- The following N lines each describe a node. Each line begins with the node's integer identifier. If the node is a leaf, it is followed by
-1
. Otherwise, it is followed by exactly three integers representing the node's children.
outputFormat
Output to stdout a single line containing True
if the tree is a super full binary tree, or False
otherwise.
4
1 2 3 4
2 -1
3 -1
4 -1
True