Editorial for LCC '21 Contest 1 S5 - Beanland


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.

Author: justinzhu

The solution covered in this editorial will use dijkstra's and binary search.

Write a function that takes an argument X and returns whether the shortest path between any two nodes is less than K after all the edges have been reduced by X.

Since N \le 400, it is sufficient for the function to run dijkstra's N times, where each time a new starting node is chosen. If the shortest path from a node u to another node v is greater than K, then the function should return false. If the shortest path between any two nodes is less than K, then the function should return true.

Now, we binary search for the answer. If the function returns true for a particular value of X, then our upper bound decreases. If the function returns false for a particular value of X, then our lower bound increases.

Time Complexity: O(logK \times N \times(N+MlogN))


Comments

There are no comments at the moment.