Problem
There are n locations ( vertices ) in a city, which are connected through streets of length 1 ( edge length = 1 ). Some of the locations have petrol stations ( colored vertex ) while others don't. People at locations with no petrol stations, go to their closest petrol station. What is the maximum distance one may have to travel to find a petrol station?
Constraints: 1 <= no of location <= 10^5
My solution
I have been able to come up with a BFS approach, where I initialize the maximum distance for the non-petrol location to maxint, then I do a BFS from every petrol location and keep updating the distances of the non-petrol location.
However, I feel like there must be a more optimal solution to this problem.
I will really appreciate if you can share a better approach.