Sponsored
Use these hints if you're stuck. Try solving on your own first.
Try to model the problem as a graph problem.
The given graph is a tree.
The problem is reduced to finding the lowest common ancestor of two nodes in a tree.
Solve with full IDE support and test cases