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
Time Complexity:
For the second subtask, compute the path from
Time Complexity:
Additional Challenge: How would you solve the problem if you were given
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.