Trees Are Fun
You are given a tree consisting of $N$ nodes where the value of node $i$ is $A_i$. You are also given an **odd** integer $K \ (1 \leq K \lt N)$. You can perform the following operation any (possibly zero) number of times: - Select an integer $x \ (-10^9 \leq x \leq 10^9)$ and two nodes $i$ and $j \ (1 \leq i \leq j \leq N)$, such that $dist(i,j)=K$; - Add $x$ to both $A_i$ and $A_j$. Find th
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start