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.
                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