Graph Theory37 sections · 1633 units
Open in Course

Problem - Path Queries

(CSES 1138)

You are given a tree. Each node has a value. Two query types: update a node's value, or ask for the sum of values on the path converting root into a given node. Root-to-node paths form a chain. If you process nodes in DFS order, each path is a prefix of the DFS traversal.

Euler tour can solve this by treating paths as prefixes. Breaking paths into these ranges lets you use data structures designed for array operations.