Graph Theory37 sections · 1633 units
Open in Course

Query Types

(What you can ask)

Subtree query: range query on [tin[v], tout[v]]. Works for sum, min, max, XOR, GCD. Path query (root to vv): prefix query to tin[v] if using add/subtract trick.

For general paths, you need more tools. Ancestor check: uu is ancestor of vv if tin[u] <= tin[v] and tout[v] <= tout[u]. This is O(1)O(1).

For path queries between arbitrary nodes, combine Euler tour with LCA to split the path into two root-to-node paths.