Editorial for Yet Another Contest 7 P3 - No More Math Homework
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
There are two aspects of this problem: determining an allocation of students to study groups, and determining the optimal adjustment to the plan.
Determining an allocation of students to study groups
The first thing to do is to rephrase this problem under a graph theory framework. We have a functional graph with edges from
Recall that every component in a functional graph is a directed cycle, where each node on the cycle is the root of a directed tree. It follows that every student will spend the first few days moving along one of these trees, and once the have reached the root of the tree, they will move around a cycle indefinitely.
Since students on the same node must belong to the same study group, the number of study groups is bounded by the sum of cycle sizes. As it turns out, this bound is always achievable; assign student
Determining the optimal adjustment to the plan
We are allowed to change the successor of a single node, and want to maximise the sum of cycle sizes. How can we do this?
After some thought, the biggest increase to the sum of cycle sizes is the maximum depth of any tree. Consider the tree with the maximum depth, and assume it has more than one node (otherwise the sum of cycle sizes cannot be increased, and it suffices to choose
- Choose
and , creating a new component. - Choose
and , increasing the size of the cycle in the current component.
Time complexity:
Comments