Knapsack on Tree
CodeChefOpen on judge ↗
You are given a rooted tree with N nodes rooted at node 1. Each node v is associated with two numbers Capacity Cv and Profit Pv. Your task is to select a subset S = {s1, s2,....sk} of nodes of this tree, such that the value Q = Ps1 + Ps2+.....+ Psk is maximized. Also, for any node v of the tree, there should not be more than Cv nodes from sub tree rooted at v in S. Input The first line of input
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