Weird Sum Queries
CodeChefOpen on judge ↗
You are given a tree containing $N$ nodes. Each node $i$ ($1 \leq i \leq N$) has a value $A_i$ associated with it. Let's define a function $F(u, v)$ where $u$ and $v$ are two nodes as: ``` def F(u, v): ans = 0 cnt = 1 currvert = u P = path from u to v while (currvert != v): ans = ans + cnt * A[currvert] currvert = (next vertex in path P) cnt++ ans = ans + cnt * A[v] re
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