Signal Chain
Challenge on lesson: Contest 3-A: Signal Chain
CHALLENGE
Difficulty: advanced+25 XP
**Problem.** A rooted tree of n relay nodes (root 1). Line 1: n. Then n-1 lines: parent of v (2..n). Then n weights w[1..n]. Then q and q lines: u v — print the sum of node weights on the path u..v (inclusive). **Constraints:** 1 <= n, q <= 200000; 1 <= w[i] <= 100; 1 <= u, v <= n. The tree may be a bamboo. **R versus W.** The graded wrong solution answers each query by climbing parents — correct output, hopeless on the bamboo load. Target: full solve within 40 minutes.
Press Submit to check your solution.
Back to lesson: Contest 3-A: Signal Chain