Editorial for IOI '96 P3 - Network of Schools


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
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 (A, B) is an edge in the graph iff school B is in the distribution list of school A. Let us first reformulate the task using graph terminology.

We use the notation p \to q if there is a (directed) path from p to q in a graph. A set of vertices D of a graph G is called dominator set of G if for each vertex q there is a vertex p in D such that p \to q.

Subtask A is to find a dominator set of G with minimal number of elements. A set of vertices CD of G is called codominator set of G if for each vertex p there is a vertex q in CD such that p \to q. A graph G is called strongly connected, if for all vertices p and q there is a path p \to q and a path q \to p in G.

Solution of subtask B is the minimal number of new edges that are necessary to make G strongly connected.

Let us denote the number of elements of a set S by |S|.

Let D be a minimal dominator set and CD be a minimal codominator set of G.

We shall prove that solution of subtask B is 0 if G is strongly connected, and \max(|D|, |CD|) otherwise.

The proof follows from statements 1 and 2. We can assume without loss of generality that |D| \le |CD|.

  1. If D is a one-element set containing p and CD contains the elements q_1, \dots, q_k then introducing the new edges (q_1, p), \dots, (q_k, p) makes G strongly connected.

    Proof: Let u, v be arbitrary vertices of G. Then there is an element q_i in CD such that u \to q_i, therefore u \to q_i \to p \to v is a path from u to v.

  2. If |D| > 1 then there are vertices p in D and q in CD such that introducing the new edge (q, p) in G makes D-[p] a new dominator set and CD-[q] a new codominator set of G.

    Proof: Since |D| > 1 there are different vertices p_1 and p_2 in D, and there are different vertices q_1 and q_2 in CD such that p_1 \to q_1 and p_2 \to q_2. Then the new edge (p, q) will be (q_1, p_2). Indeed, any vertex u that was reachable from p_2 by the path p_2 \to u will be reachable from p_1 by p_1 \to q_1 \to p_2 \to u and for any path v \to q_1 there will be a path v \to q_1 \to p_2 \to q_2 in the new graph.

It is obvious that a codominator set of a graph G is a dominator set of the transposed graph G^T and conversely. Therefore we can compute the minimal codominator set of G by transposing G 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 D that is produced by this algorithm is a dominator set. Assume that D contains the vertices p_1, \dots, p_k and D is not minimal, i.e. there is a minimal dominator set Q that contains vertices q_1, \dots, q_l, and l < k. Since D is a dominator set and Q is a minimal dominator set, it follows that for each q_i in Q there is a unique p_i in D such that q_i is reachable from p_i by a path p_i \to q_i. But every vertex is reachable from Q, therefore p_k is also reachable from some vertex in Q, say q_i \to p_k. We obtained that there is a path p_i \to q_i \to p_k from p_i to p_k. The algorithm has executed both Search(p_i) and Search(p_k). Either Search(p_i) or Search(p_k) was executed first, the vertex p_k was excluded from D because p_k is reachable from p_i. This contradicts the assumption that D is not minimal.

The algorithm above can be modified to avoid set operations union (+) and difference (-). Indeed, when Search(p) is executed, we can include p in the set Dominated and exclude p from D.


Comments

There are no comments at the moment.