Editorial for APIO '09 P2 - The Siruseri Convention Centre
Submitting an official solution before solving the problem yourself is a bannable offence.
Consider the intervals as vertices and add an edge between vertices if they overlap. This gives an interval graph the problem is to find a lexicographically smallest maximal independent set (MIS) of such an interval graph.
Finding a maximal independent set: Finding a maximum sized candidate is easy, a greedy algorithm suffices. Sort the intervals by increasing order of endpoints and process them in this order. Include an interval if it does not overlap with any of the intervals selected earlier. This can be done in linear time after the sorting.
Lexicographically earliest: Now, to find the lexicographically least among all maximum independent sets, where the order is defined by the order in which the vertices appear in the input. Greedily add the vertices in the order of their appearance in the input, and find out at each step if the current set can be extended to an independent set of maximum size (this can be done in linear time using the algorithm outlined above.) This gives an algorithm.
Lexicographically earliest: For clarity in the explanation, assume that no interval is completely contained in another interval. This assumption can be eliminated with a somewhat more elaborate argument along the same lines and the details are omitted here.
Preliminaries:
- We will think of the intervals as nodes of a graph. Two nodes have an edge if the corresponding intervals intersect. The label of node is .
- The required solution is the lexicographically earliest maximum independent set. By , where is a subset of we will mean any MIS of the subgraph induced by .
- Define .
Observation 1 Our simple solution to (non-lexicographic) MIS shows that
is a solution.
Subroutine that takes and outputs in time: Using the first observation, the size of the MIS of is . This subroutine will essentially guess the bits of the correct . The data structure to do this (created in the preprocessing stage) is arrays where .
Main Program First compute the size of the MIS, . Take node with earliest time. Neighbors of are for some . These can be found by binary search in time. To test whether can be included in a MIS, we need to check if . This can be done in time using the subroutine.
Suppose passed the test. Take the next node (by input ordering). Now we first locate (in time through binary search) which of the two sides or does belong to. If it belongs to neither, then was a neighbor of , and so fails the test. Otherwise, suppose was in , and its neighbors were where . Now we need to check if .
The data structure required for this part is a segment tree (or anything that can support insertions, and queries asking for the smallest element in the data structure larger than a number given in the query).
Comments