Graph Theory37 sections · 1633 units
Open in Course

Core Idea - Path as Prefix

(DFS order property)

Path from root to vv includes all ancestors of vv. In Euler tour, these ancestors have tin[u] <= tin[v] and tout[u] >= tout[v]. If you store values at entry times, the path sum from root to vv is the sum of arr[tin[u]] for all uu on the path.

But ancestors are not contiguous in the flattened array. You need a different approach. Breaking paths into these ranges lets you use data structures designed for array operations.