Editorial for IOI '96 P3 - Network of Schools
Submitting an official solution before solving the problem yourself is a bannable offence.
The network of schools can be represented by a directed graph whose vertices are the schools and is an edge in the graph iff school is in the distribution list of school . Let us first reformulate the task using graph terminology.
We use the notation if there is a (directed) path from to in a graph. A set of vertices of a graph is called dominator set of if for each vertex there is a vertex in such that .
Subtask A is to find a dominator set of with minimal number of elements. A set of vertices of is called codominator set of if for each vertex there is a vertex in such that . A graph is called strongly connected, if for all vertices and there is a path and a path in .
Solution of subtask B is the minimal number of new edges that are necessary to make strongly connected.
Let us denote the number of elements of a set by .
Let be a minimal dominator set and be a minimal codominator set of .
We shall prove that solution of subtask B is if is strongly connected, and otherwise.
The proof follows from statements 1 and 2. We can assume without loss of generality that .
If is a one-element set containing and contains the elements then introducing the new edges makes strongly connected.
Proof: Let , be arbitrary vertices of . Then there is an element in such that , therefore is a path from to .
If then there are vertices in and in such that introducing the new edge in makes a new dominator set and a new codominator set of .
Proof: Since there are different vertices and in , and there are different vertices and in such that and . Then the new edge will be . Indeed, any vertex that was reachable from by the path will be reachable from by and for any path there will be a path in the new graph.
It is obvious that a codominator set of a graph is a dominator set of the transposed graph and conversely. Therefore we can compute the minimal codominator set of by transposing and then computing the minimal dominator set of the transposed graph.
The strategy for computing a minimal dominator set is the following. (We use Pascal terminology for set operations)
Dominated:=[];
D:=[];
While there is a p not in Dominated Do Begin
Search(p);(* put all vertices in set Reachable that are reachable from p*)
Dominated:=Dominated+Reachable;
D:=D-Reachable; (* exclude all elements of D that are in Reachable *)
Include p in D;
End;
Evidently, the set that is produced by this algorithm is a dominator set. Assume that contains the vertices and is not minimal, i.e. there is a minimal dominator set that contains vertices , and . Since is a dominator set and is a minimal dominator set, it follows that for each in there is a unique in such that is reachable from by a path . But every vertex is reachable from , therefore is also reachable from some vertex in , say . We obtained that there is a path from to . The algorithm has executed both and . Either or was executed first, the vertex was excluded from because is reachable from . This contradicts the assumption that is not minimal.
The algorithm above can be modified to avoid set operations union (+) and difference (-). Indeed, when is executed, we can include in the set Dominated and exclude from .
Comments