Editorial for DMOPC '18 Contest 3 P4 - Bob and English Class
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For the first subtask, it's optimal to connect the rightmost to the leftmost, second rightmost to the second leftmost, etc. A prefix sum can be used to speed this up.
Time Complexity:
For the second subtask, precompute the distance between each pair of students using BFS or DFS. Then, brute-force all possible configurations of pairs.
Time Complexity:
For the third subtask, root the tree arbitrarily. We think of the distances between pairs as each student moving up to their LCA. Now let
Time Complexity:
For the final subtask, we realize that the solution to the third subtask is absolutely awful. Root the tree at the centroid of the students (not the centroid of the entire tree!). Again, consider this problem. If we merge the children of the centroid with their maximum possible
Time Complexity:
Comments