Dipole Moment
You are given a tree with $N$ nodes, numbered from $1$ to $N$. It is rooted at node $1$. We call the simple path between node $A$ and node $B$ to be vertical if node $A$ lies on the path from the root to $B$ or node $B$ lies on the path from the root to $A$. In other words, [LCA](https://en.wikipedia.org/wiki/Lowest_common_ancestor) ($A,B$) must be $A$ or $B$. And in such cases, we define a n
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