Pursuit of Happiness
CodeChefOpen on judge ↗
You are given a tree consisting of $N$ nodes numbered through $1$ to $N$, where the $i^{th}$ node has a value $A_i$. A tree is a connected, undirected, and acyclic graph. Chef chooses all the $(u,v)$ such that $u \neq v$ and chef's special node $s$ ($s \neq u$ and $s \neq v$) lies on the simple path from $u$ to $v$, and finds the happiness value of each pair. The happiness value of any pair
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