Euler Tour Technique — Tree Flattening (tin / tout)

Build O(n) Subtree query O(log n) Ancestor test O(1) Space O(n)
Tree (DFS visit order)
Flattened array — order[t] (node entered at time t)
flat[t] = value of order[t] (Fenwick is built over this)
tin / tout per node
Pick a tree, then Run DFS or Step to flatten it. Watch tin/tout fill in and each subtree become a contiguous range.
timer: 0
current: -
nodes done: 0
subtree sum: -
Fenwick ops: 0
current node / tin finished (tout set) selected subtree range Fenwick cell touched

Complexity

OperationCostHow
Build flatten (DFS)O(n)one traversal, tin/tout
Subtree → rangeO(1)read [tin[v], tout[v]]
Subtree sizeO(1)tout[v] - tin[v] + 1
Ancestor testO(1)interval containment
Subtree sumO(log n)Fenwick range query
Point updateO(log n)Fenwick add at tin[v]

Operation Log