Skip to content

1976. Number of Ways to Arrive at Destination #1469

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the number of ways to travel from intersection 0 to intersection n-1 in the shortest possible time using bidirectional roads. The solution involves using Dijkstra's algorithm to find the shortest paths and then dynamic programming (DP) to count the number of ways to reach the destination using those shortest paths.

Approach

  1. Compute Shortest Paths: Use Dijkstra's algorithm to compute the shortest time from intersection 0 to all other intersections. This helps in identifying the shortest paths.
  2. Construct DAG: Build a Directed Acyclic Graph (DAG) where edges represent the shortest paths. For each road, check if it contributes to the shortest path in either direction and…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Mar 23, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Mar 23, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants