← All problemsSign in

Alternating edges

You are given a weighted tree consisting of $n$ vertices numbered from $1$ to $n$. A tree is a connected undirected graph without cycles. If $w_1, w_2...w_m$ are the weights of the edges lying on the simple path starting from node $a$ and ending at node $b$, then we define the alternating-distance from $a$ to $b$, $altdist(a,b)$ as the sum of weights of alternate edges starting from $w_1$ (i.e $w

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