Editorial for WC '16 Contest 4 S2 - Pawpsicles
Submitting an official solution before solving the problem yourself is a bannable offence.
Consider an implicit graph with nodes, with each node representing a possible state which Nick can be in. Each node can be described by two values – his current location , and the next location type which he needs to visit (, with representing that he's already completed all steps of his Pawpsicle operation). His initial state is , and he wants to reach a state (for any ) as quickly as possible. By travelling along roads and visiting the correct types of locations, he can move between these states in certain amounts of time. These transitions between states correspond to weighted, directed edges in the implicit graph.
At this point, we've reduced the problem to finding the shortest path on a graph, a well-known task which can be accomplished using Dijkstra's algorithm in time, where and are the number of nodes and edges in the implicit graph, respectively. In this case, , and is in . What remains is implementing Dijkstra's, and handling the implicit graph's edges properly. For example, the -th road can be used to go from state to for any value of , and for each node such that , there exists a weight- edge from state to . We want to stop as soon as we reach any node with .
Comments