Maximum Product Walk
You are given a tree with $N$ vertices. Vertex $i$ has the integer $A_i$ written on it. It is guaranteed that $A_i \ne 0$. A *walk* in the tree is a sequence of vertices $(x_1, x_2, \ldots, x_k)$ such that there exists an edge between $x_i$ and $x_{i+1}$ for each $1 \le i \lt k$. The length of such a walk is said to be $k$. Note that in particular, it is allowed for vertices to repeat in a walk
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