Dynamic Trees and Queries
Given a directed tree with N nodes. You need to process M queries. Each node has a key and a value, a node is referenced by its key. N nodes have keys from 0 to N-1. Root always has the key equal to 0. Queries can be of the following 4 types: 1. Given a key of a node present in the tree, append a child node to it. The new node gets the smallest never-used positive integer as its key. The value of
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