Tree Query
You are given a tree with $N$ vertices (numbered $1$ through $N$); vertex $1$ is the root. Initially, for each valid $i$, the $i$-th vertex has a weight $w_i$. You should perform a sequence of $Q$ operations of the following two types: 1. Add $x$ to the weight of vertex $v$. 2. Add $x$ to the weight of each vertex in the subtree of vertex $v$ (including $v$). Let's define a function $f(u) = \
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