← All problemsSign in

Sum on Tree

CodeChefRating 2814Open on judge ↗

You are given a tree with $N$ nodes (numbered $1$ through $N$) and $N-1$ edges. Each node has a value; let's denote the value of node $x$ by $W_x$. Next, let's define the value of a simple path $v_1, v_2, \dots, v_k$ as $\sum_{i=1}^k i \cdot W_{v_i}$. A simple path in a tree is a sequence of nodes $v_1, v_2, \dots, v_k$ such that: - $k \ge 1$ - there is an edge between nodes $v_i$ and $v_{i+1

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