Editorial for IOI '19 P2 - Split the Attractions
Submitting an official solution before solving the problem yourself is a bannable offence.
Subtask 1
In this subtask, the given graph is a path or a cycle. Therefore, the answer is always YES and a solution can be easily found by partitioning a path: into , , and . In case of a cycle, we can cut the cycle in any place and apply the similar solution as we had in path.
Subtask 2
In this subtask, the answer is always YES as follows. Let us assume that . Find a connected subgraph of size (like using DFS or any graph traversing algorithm) as subset , construct subset consisting of an arbitrary vertex outside of , and other vertices are set .
Subtask 3
In this subtask, the given graph is a tree. The solution is similar to that of the last subtask but the cases to be considered are easier. Without loss of generality suppose . One solution is to run a DFS on an arbitrary vertex to find some arbitrary spanning tree and find a vertex such that the size of the subtree of [including ] denoted by is at least , but the sizes of the subtrees of all children of are less than . Remove the edge between and the parent of which partition the tree into two connected components. If both of the components have a size more than , then the answer is YES. Otherwise, the answer is no since removing from the original graph only produces components of size less than . If the answer is YES, then a connected subgraph of size (namely ) from the smallest component, and a connected subgraph of size (namely ) from the smallest component can be extracted (since , the size of the larger component is at least ). Finally, consists of all of the remaining vertices.
Subtask 4
The input of this subtask is similar to that of the final subtask. However, since the limits for and are more restricted, one can use instances of DFS instead of only one.
Subtask 5
Similar to the solution of subtask 3, assume we run a DFS on an arbitrary vertex and found a vertex such that but the sizes of the subtrees of the children of are all smaller than . Note that other edges outside the DFS tree are backward edges. Hence, the children of may have backward edges to or the ancestors of , but no edge exists between them. Suppose we want to partition the graph into two connected components by only considering the edges of the DFS tree and removing the edge between and the parent of . In this way the graph is partitioned into part consisting of and its subtree and consisting of all other vertices. Before proceeding, we check every child of (in an arbitrary order) like and if the following conditions hold, we remove its subtree from and add it to . The subtree of has a backward edge to the ancestors of . The size of after removing the subtree of is still at least . By doing so, one by one, we may encounter a child of , namely , such that and . Hence, . In the other case, either , which is also good since , or and the answer is NO, since is a cut vertex such that removing it from the original graph produces several components where all of them are of size less than .
Comments