Skip to main content

Practice · 4 of 4

Sprint D — Path Values (SELF-TIMED 45)

CHALLENGE
Difficulty: advanced+25 XP

**SELF-TIMED: 45 minutes.** Two ideas fused; careful edge cases decide. **Bài toán.** A tree with n vertices, each vertex i having value a[i]. Answer q queries (u, v): print the XOR of a[i] over all vertices on the unique path from u to v (each visited vertex counted once). **Constraints:** 1 ≤ n, q ≤ 200000; 1 ≤ a[i] ≤ 1000; the tree is given by n − 1 edges. **Input:** line 1: n and q; line 2: n values; then n − 1 lines of edges; then q lines u v. **Output:** q lines, each the path XOR.

Back to lesson: Practice: Contest Sprints — Four Clocks