Practice · 1 of 3
Treasury Audit
CHALLENGE
Difficulty: advanced+25 XP
**Problem.** A rooted tree (root 1) of n accounts. Line 1: n q. Then n-1 lines: parent of v. Then q ops: "1 v x" sets account v's balance to x; "2 v" prints the total balance in v's subtree. **Constraints:** 1 <= n <= 200000; 1 <= q <= 100000; 0 <= x <= 100. Subtree re-walks per query are the classic near-miss.
Press Submit to check your solution.
Back to lesson: Practice: Mixed Drill — Trees and Strings