I'll walk you through a complete example. Tree structure: node (root) has children and . Node has child . Each node holds a value: , , , .
DFS visits nodes in order: . Entry times (when first visited): node gets , node gets , node gets , node gets . Exit times mark when you leave each subtree.
Flatten values by entry time into arr = [4, 2, 1, 5]. Node 's subtree spans indices in this array. Sum those positions: . Update node 's value to by changing arr[2]. Now node 's subtree sums to .