Chef Chooses a Subset
Chef has a tree with N nodes numbered 1 through N. A subset S of nodes of the tree is called connected if, for any two nodes from S, the simple path between these two nodes in the tree contains only nodes which belong to S. Chef defines the cost of a connected subset S as |S| · AND(S). Here, |S| denotes the size of the set S and AND(S) denotes the bitwise AND of indices of all nodes from S. Che
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