Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For the ith query, find the distance from node_i to every other node in the tree.
We can use a BFS to find the distances.
Use DFS to find all the nodes on the path from start_i to end_i.