← All problemsSign in

Lazy Ancestors

CodeChefRating 2723Open on judge ↗

You are given a tree consisting of $N$ nodes and $N-1$ edges. The $i$-th node has value $A_i$. Let $d(x, y)$ denote the number of edges on the (unique) shortest path between $x$ and $y$. For each node $u \ (1 \leq u \leq N)$, compute the following quantity: $$ \sum_{i=1}^N \left \lfloor \frac{A_i}{2^{d(u, i)}} \right\rfloor $$ Here, $\left\lfloor \ \right\rfloor$ denotes the [floor function](ht

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start