Design algorithm to count simple paths between two DAG vertices
Analyze the design algorithm to count simple paths between two dag vertices.
Examples
Input:"test_input_1"
Output:"output_1"
Input:"test_input_2"
Output:"output_2"
Hints
Consider using Depth-First Search (DFS) to traverse the DAG and count paths, but optimize it to avoid redundant calculations.
Explore dynamic programming (DP) where `dp[u]` represents the number of paths from vertex `u` to the target vertex `v`, and build the solution bottom-up.
Leverage topological sorting to process vertices in an order that ensures all dependencies (incoming edges) are resolved before computing `dp[u]`.
Design algorithm to count simple paths between two DAG vertices
Analyze the design algorithm to count simple paths between two dag vertices.