Leetcode Problem 1976. Number of Ways to Arrive at Destination
1976. Number of Ways to Arrive at Destination
Leetcode Solutions
Dijkstra's Algorithm with Path Counting
Initialize a priority queue (min-heap) for Dijkstra's algorithm, a distance array dist with infinity values, and a ways array ways with zeros.
Set dist[0] to 0 and ways[0] to 1, as we start from node 0.
Add the source node (0, 0) to the priority queue.
While the priority queue is not empty:
a. Pop the node with the smallest distance from the queue.
b. Iterate over its neighbors.
c. If a shorter path to a neighbor is found, update its distance and ways.
d. If a path with the same length is found, add the current node's ways to the neighbor's ways.