Save The Day
CodeChefOpen on judge ↗
Problem description. We have an undirected tree with n nodes, numbered 0 through n-1. You are given its description: a int[] p with n-1 elements. For each valid i, there is an edge between nodes p[i] and (i+1). There are k tokens on the tree, each in a different node. You are given a int[] position. The elements of position are the numbers of the nodes that contain the tokens. A demon has place
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