Editorial for WC '18 Finals S5 - Opening Weekend
Submitting an official solution before solving the problem yourself is a bannable offence.
We'll represent the network of cities and roads as a tree, rooted at an arbitrary node (node ). Our overall approach will be to consider vehicle heights in decreasing order, in a line-sweep-like manner. Given the current vehicle height, we'll let be the node to which vehicles of that height will drive to next from node (equal to itself if vehicles would remain there). Initially, for arbitrarily large vehicle heights, for each (as no roads can be used). As the vehicle height decreases, for each , may increase as roads leading to higher-numbered cities become usable. For each node , if we sort its incident roads in non-increasing order of tunnel height ( time), we can precompute the sequence of vehicle heights at which will increase (and what values it will increase to), each of which represents an event of interest in the overall line sweep. On top of these events, we'll have more events, one per moviegoer.
Assuming we maintain all nodes' values as we proceed through the line sweep, we'll have the appropriate values when processing each moviegoer , at which point we'll want to determine the final node they'll arrive at if repeatedly moving from their current node (initially ) to (until ). However, each moviegoer could perform such moves, meaning that naive simulation yields a time complexity of and is too slow for full marks.
In order to optimize this approach, we'll begin by applying heavy-light decomposition to the tree. We'll still maintain the individual values of nodes not on heavy paths. However, for each heavy path, we'll instead maintain a set of intervals of contiguous subsequences of nodes along the path which all lead to a single node. For example, consider the following heavy path (with dashes representing currently-usable edges and underscores representing unusable ones): 1-3-5-2_7-4-6
. It can be reduced into intervals: , , .
Each time a line sweep event causes a node's value to change, we can update the above representation as necessary in time (with care taken when updating a heavy path's interval set to merge/split intervals appropriately). And each time we need to simulate a moviegoer's route, they'll only move along heavy paths (each of which may be processed in time) and other nodes (each requiring time), for a total of . This brings us to an overall time complexity of .
Comments