Editorial for Another Random Contest 1 P6 - Smash Bros
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
Since node is equal to , Andy can go straight to . Thus, the answer is the shortest distance from to .
Time Complexity:
Subtask 2
Let's call the shortest distance between and to be .
For any point , there must exist a point such that the shortest path goes . This path results in a cost of ( is ignored because all nodes on the path have already been unlocked when traversing from to ).
Building on that, let's analyze .
can be separated into two parts, and . doesn't depend on , and can be precomputed by running shortest path twice from nodes and . For every query, run shortest path from node and determine the minimum value of for all possible node .
Time Complexity:
Subtask 3
Set up an additional node , and build new edges with every single node in the graph. The edge between and any node is going to have a weight of . Run shortest path algorithm from node , and the shortest path from node to any node is the answer for when . Thus, each query can be answered in .
Time Complexity:
Comments