teacher
Sign in

Euler Tour on Trees

Flatten a tree with tin and tout times so every subtree becomes one array range, then use a Fenwick or segment tree on it.

40 minCF 1900–23004 interactive8 problems

The problem

You have a rooted tree where each node holds a number. Queries change one node's value, ask for the sum over the subtree of a node (the node and all its descendants), or ask for the sum on the path from the root to a node. A tree is not an array, so range structures do not apply directly.

1 of 10