Left child, right sibling (1)

Left child, right sibling is the name of a known bijection between the
general trees and the non empty binary trees with empty right subtree.
To convert a general tree to binary tree the first child (starting on
the left) is made its leftmost child of each node and the remaining
nodes one after another are made the right child of the previous
sibling.

(To see an instance with a tree with the same shape than the first tree
of the input-output instance, consult the pdf or ps version of this
wording.)

Write a program that reads the shape of various general trees, and for
each one prints the height of the corresponding binary tree.

Input

Input starts with m, the number of trees that must be treated The
description of the m trees follow as is explained at the exercise REREG,
with two exceptions: The values are not given, because the content of
the nodes here is not important. The number of nodes is neither given,
because you do not need to store the trees in any vector to solve this
exercise.

Output

Your program must print the height corresponding to the binary tree of
each given tree.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:16:19.941Z

© Jutge.org, 2006–2026.
https://jutge.org
