321. Height of a Tree
Print the height of the tree, counting nodes rather than edges. A single node therefore has height 1.
The recursion is the shape every problem in this topic uses: the height of a tree is one more than the taller of its two subtrees, and the height of an absent subtree is 0.
That last part is the base case, and it is worth being clear that "absent
subtree" and "leaf" are different things. A leaf is a real node with two absent
children, so it gets 1 + max(0, 0), which is 1.
Constraints - `1 ≤ n ≤ 100000` - `-1000000000 ≤ value ≤ 1000000000` - The input always forms a valid tree rooted at node 1.
Input
The first line contains an integer n, the number of nodes.
The second line contains n values, where node i holds the ith value.
Each of the next n lines contains two integers, the left and right child of
node i, using 0 for no child. Node 1 is the root.
Output
Print one integer, the height of the tree in nodes.