342. Is the Tree Symmetric
Print Yes if the tree is a mirror image of itself about the root, and No
otherwise.
1 1
/ \ / \
2 2 Yes 2 2 No
/ \ / /
3 3 3 3
Both trees have identical VALUES. The second is not symmetric because both 3s hang on the left, so the shape does not mirror.
That is the trap this problem exists for, and comparing values alone passes it. The comparison has to be structural: walk the two subtrees together, matching the left of one against the RIGHT of the other at every step.
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 Yes or No on one line.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.