Sponsored
Use these hints if you're stuck. Try solving on your own first.
Find the parent of each node.
A valid tree must have nodes with only one parent and exactly one node with no parent.
Solve with full IDE support and test cases