0

Problem Statement: https://www.hackerrank.com/challenges/jack-goes-to-rapture

One of the solutions is use modified Dijkstra's Algorithm.

Original:

For a vertex u,
Forall vertices v, instead of updating the distance by,
alt = distance(u) + weight(u, v)
if(alt < distance(v)) distance(v) = alt

Modified:

For a vertex u,
Forall vertices v, instead of updating the distance by,
alt = max(distance(u), weight(u, v))
if(alt < distance(v)) distance(v) = alt

I am not able to get the intuition behind alt = max(distance(u), weight(u, v)) which is the maximum weight of the edges in the shortest path.

Could someone explain the intuition behind the solution.

Abhishek
  • 432
  • 5
  • 19

1 Answers1

2

If a passenger travels from station A to station B, he only has to pay the difference between the fare from A to B and the cumulative fare that he has paid to reach station A [fare(A,B) - total fare to reach station A]. If the difference is negative, he can travel free of cost from A to B.

So, the real weight of edge(A, B) is max(0, fare(A, B) - min_distance(A)). So the cumulative distance will be:

min_distance(A) + max(0, fare(A, B) - min_distance(A)) = max(min_distance(A), fare(A, B))

DAle
  • 8,990
  • 2
  • 26
  • 45
  • Thank you! Is there a standard term for this min-max simplification? – Abhishek Apr 19 '17 at 12:38
  • Don't know about simplification, but this problem (modified a bit) has a standard name. From [wiki](https://en.wikipedia.org/wiki/Widest_path_problem): "A closely related problem, the **minimax path problem**, asks for the path that minimizes the maximum weight of any of its edges." – DAle Apr 19 '17 at 12:52