TomorrowLand
CodeChefOpen on judge ↗
Carol lives in Tomorrowland. Tomorrowland consists of $n$ cities connected by $n$ - 1 roads. Exactly one simple path exists between every pair of cities in Tomorrowland. Each city $i$ has two values – ($k_i$ and $r_i$). The tree is rooted at node 1. On the 100th anniversary of Tomorrowland, to check how the cities are cooperating with each other, the mayor of Tomorrowland wanted to calculate the
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