Editorial for IOI '17 P3 - Toy Train


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.

For a set of stations S, define f_A(S) as the set of all stations such that if the train is placed on them, Arezou can play in a way that the train reaches one of the stations in S at some point, regardless of Borzou's moves (therefore S \subseteq f_A(S) by definition). We define f_B(S) similarly.

Initially, let T = S, and we iteratively add stations to T such that eventually T becomes equal to f_A(S).

While there exists a station v that satisfies one of the following conditions, we add v to the set T:

  1. v is owned by Arezou, and there exists an outgoing track from v that arrives at a station already in T.
  2. v is owned by Borzou, and all of the outgoing tracks from v arrive at the stations already in T.

Similarly, we can compute f_B(S). Notice that both f_A(S) and f_B(S) can be computed iteratively in time \mathcal O(n+m).

Now let R be the set of all the charging stations. By definition, for every station v \notin f_A(R), Borzou can win the game if the train is initially placed on v.

Therefore, we can solve the problem as follows:

  1. If f_A(R) is the set of all stations, Arezou can win the game for all initial stations.
  2. Otherwise:
    1. Let X be the set of all stations not in f_A(R).
    2. Borzou can win the game if the initial stations are in f_B(X).
    3. Remove f_B(X) from the graph and solve the problem recursively for the remaining stations.

This algorithm runs in time \mathcal O(nm).


Comments

There are no comments at the moment.