Chef and Lollipops 2
CodeChefOpen on judge ↗
Now that Chef has a lot of lollipops, some of Chef’s friends are jealous of him. Chef’s friends have trapped him in a tree consisting of $N$ nodes (numbered $1$ through $N$), where node $1$ is the $root$ $node$. On each node there's a friend $i$ who will take $A[i]$ lollipops from chef. But there's a catch. Chef's friends asked him to select any $K$ different nodes and visit them one by one.
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