##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Shortest/longest path in DAGs, counting paths, and DP with topological order.
The Goal
No cycles = DP works
Linear ordering of nodes
Process in topological order
Knowledge check
Better than Dijkstra
What dp[u] means
Step by step process
Walking through an instance
Flip the minimization
Scheduling and critical paths
Knowledge check
CSES 1680
Edge weights are 1
Networks can have cycles
dp[u] = max cities to u
Backtracking from destination
Complete solution
Handling IMPOSSIBLE
Step by step trace
summary
How many ways to reach
CSES 1681
dp[u] = number of paths to u
Paths are independent
Output modulo 10^9+7
Complete solution
Tracing the DP
Knowledge check
Base case matters
Apply after every operation
Initialize multiple base cases
Sum over all endpoints
Reverse edges for DP
Paths through a node
Knowledge check
CSES 1673
Infinite score problem
Negate for maximization
Reachable from 1 and reaches n
Complete solution
Cycles break the pattern
Trees are DAGs
Updating distance estimates
Linear ordering of DAG nodes
LeetCode 210
LeetCode 787 with constraint
Problem recognition
State space graphs
What we learned