Graph Theory37 sections · 1633 units
Open in Course

Game Routes - Core Idea

Summing paths instead of max

The state is ways[v], the number of ways to reach level vv from level 11. The base case is ways[1] = 1 (one way to be at the start). The transition is: for each edge uvu \to v, add ways[u] to ways[v]. This says "every way to reach uu extends to a way to reach vv". Why does this work?

Because the graph is a DAG, there are no cycles. Each path is counted exactly once. When you process vv in topological order, you've already counted all ways to reach its predecessors uu, so you can sum them safely.