I am using BFS to find distance of each city from king’s city(capital).Then for each query, i am comparing the distance of LCA of chef’s city and each city having product p.Problem link.
Here is my solution.
A solution implemented in the same way got accepted.Check this solution.
Where am i going wrong ? Both the codes are implemented in nearly same way.