Editorial for WC '18 Finals S4 - Posters


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.

Let's think of the network of cities and highways as a tree rooted at node A. We'll then approach the problem with dynamic programming on this tree. Let DP[i][a][b][x] be the minimum number of distinct nodes which must be visited by Bo Vine in node i's subtree such that:

  • All movie theatres in node i's subtree will be visited by somebody
  • If a = 1, the Head Monkey will visit node i, and otherwise if a = 0, she will not
  • If b = 1, Bo Vine will visit node i, and otherwise if b = 0, he will not
  • The Head Monkey will visit x distinct nodes in node i's subtree

Starting from some initial node, visiting k distinct nodes (including the initial one), and then returning to that initial node requires 2 \times (k-1) hours. Therefore, for a given b value representing whether or not Bo Vine will visit the root (node A), and a given x value representing how many distinct nodes the Head Monkey will visit in total, 2 \times (\max(x, DP[A][1][b][x])-1) is the total number of hours that will be required. If these DP values could be computed, then we could consider all \mathcal O(N) possible pairs of (b, x) and take the smallest of their corresponding times.

What remains is computing the DP values, which we'll do recursively starting from the root. The general approach will be a standard one – for each child c of a given node i, we'll consider all possible triples of (a_1, b_1, x_1) for node i and all possible triples of (a_2, b_2, x_2) for node c, and update node i's DP values based on sums of the form DP[i][a_1][b_1][x_1]+DP[c][a_2][b_2][x_2]. The details of interest concern exactly which states and transitions are actually valid, and are as follows:

  • If C_i = 1 and a = b = 0, then the state is invalid (node i's movie theatre must be visited)
  • If i = B and b = 0, then the state is invalid (Bo Vine must visit node B)
  • If a_1 = 0 and a_2 = 1, then the transition is invalid (the Head Monkey can't reach node c without passing downwards through node i)
  • If B is within c's subtree, b_1 = 1, and b_2 = 0, then the transition is invalid (Bo Vine can't reach node i without passing upwards through node c)
  • If B is not within c's subtree, b_1 = 0, and b_2 = 1, then the transition is invalid (Bo Vine can't reach node c without passing downwards through node i)

To implement the above checks, we can pre-compute whether or not B is within each node i's subtree in a total of \mathcal O(N) time. Given that, the overall time complexity of this dynamic programming approach comes out to \mathcal O(N^3).


Comments

There are no comments at the moment.