Editorial for WC '18 Finals S4 - Posters
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 . We'll then approach the problem with dynamic programming on this tree. Let be the minimum number of distinct nodes which must be visited by Bo Vine in node 's subtree such that:
- All movie theatres in node 's subtree will be visited by somebody
- If , the Head Monkey will visit node , and otherwise if , she will not
- If , Bo Vine will visit node , and otherwise if , he will not
- The Head Monkey will visit distinct nodes in node 's subtree
Starting from some initial node, visiting distinct nodes (including the initial one), and then returning to that initial node requires hours. Therefore, for a given value representing whether or not Bo Vine will visit the root (node ), and a given value representing how many distinct nodes the Head Monkey will visit in total, is the total number of hours that will be required. If these values could be computed, then we could consider all possible pairs of and take the smallest of their corresponding times.
What remains is computing the values, which we'll do recursively starting from the root. The general approach will be a standard one – for each child of a given node , we'll consider all possible triples of for node and all possible triples of for node , and update node 's values based on sums of the form . The details of interest concern exactly which states and transitions are actually valid, and are as follows:
- If and , then the state is invalid (node 's movie theatre must be visited)
- If and , then the state is invalid (Bo Vine must visit node )
- If and , then the transition is invalid (the Head Monkey can't reach node without passing downwards through node )
- If is within 's subtree, , and , then the transition is invalid (Bo Vine can't reach node without passing upwards through node )
- If is not within 's subtree, , and , then the transition is invalid (Bo Vine can't reach node without passing downwards through node )
To implement the above checks, we can pre-compute whether or not is within each node 's subtree in a total of time. Given that, the overall time complexity of this dynamic programming approach comes out to .
Comments