Saturday Night Dijkstra's Algorithm II
Another problem that requires use of Dijkstra's Algorithm for efficiency's purposes. Basically we have a directed weighted graph, and want to find the min distance between a certain node and any marked node. Approach goes as follows: 1/ Build a quick-access graph using a hashtable. Remember that you can have multiple edges [u,v,w] where u and v are the same. Handle that in the creation method 2/ Make a quick-access look-up table for the marked nodes 3/ Use a ascending priority queue to speed up the BFS algorithm 4/ As you do the BFS, unfortunately there is no easy way to stop it since you may always find a min route. Instead, rely on the pruning to not add to the queue any path larger than the min so far 5/ Handle some edge cases here and there, such as no-path found Code is down below, cheers, ACC Find the Closest Marked Node - LeetCode 2737. Find the Closest Marked Node Medium 10 0 Add to List Share You are given a positive integer n which is the number of nodes of a 0-ind