## Editorial for DMOPC '17 Contest 2 P3 - Bad Bunnies

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Author:

For the first subtask, brute force to find the distance from each node to each rabbit. Then, check along the path from to to find the answer.

**Time Complexity:**

For the second subtask, compute the path from to . Partition the tree by deleting the edges of the path. Several subtrees rooted from nodes on the path are created. Compute the minimum distance from each node of the path to a rabbit in its subtree using simple tree DP. The final answer is the minimum of these values.

**Time Complexity:**

**Additional Challenge:** How would you solve the problem if you were given queries, the of which has and as the start and endpoints, respectively, of the path?

## Comments

Can someone give a hint on how to solve the additional challenge. I have somewhere read that using 2 dfs, this can be achieved but HOW??

Idk if this is an overkill, but you can precompute each node's distance to the closest rabbit, then use a modified lca to answer the queries, kinda like distribution channel.

That is indeed the correct solution.