324. Largest Value in the Tree
Print the largest value stored anywhere in the tree.
The traversal is unchanged and the base case is not. An empty subtree has no maximum at all, so there is no value you can return for it that is safe.
Returning 0 is the tempting mistake, and it is wrong for any tree whose values are all negative. Either start from the root's own value and compare downwards, or return something smaller than any possible value from the empty case. The test with three negative values exists to make the difference visible.
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 largest value in the tree.