The distance part clicked fast for me since it's basically Dijkstra.
Use Dijkstra's algorithm to compute shortest distances from the source to all nodes, while maintaining a count of shortest paths to each node. When relaxing an edge, if a shorter distance is found, update the distance and set the path count to the count of the predecessor; if an equal distance is found, add the predecessor's path count to the current node's count. Finally, return the path count for the target node, or 0 if unreachable.
Pro tip: Mention that path counts can grow exponentially, so use a large integer type (e.g., Python's arbitrary-precision int or Java's BigInteger) or take modulo if the problem specifies it. Also, clarify whether the graph can have zero-weight edges, as that affects the algorithm's correctness.
Ask about graph size, edge weight range, whether zero-weight edges exist, and if the count should be modulo something. This ensures you handle edge cases correctly.
Select Dijkstra's algorithm because it efficiently finds shortest paths in graphs with non-negative weights. Mention that BFS works only for unweighted graphs, and Bellman-Ford is overkill.
Use a priority queue for Dijkstra, an array for distances, and an array for path counts. Initialize distances to infinity and path count of source to 1.
For each edge (u, v) with weight w, if dist[u] + w < dist[v], update dist[v] and set count[v] = count[u]. If equal, add count[u] to count[v].
After the algorithm, if dist[target] is still infinity, return 0; otherwise return count[target].
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.