Nearest Color
You have to process $Q$ queries on a rooted tree. Each node of the tree has a label and a color. Initially, the tree consists of a single node (the root) with label $1$ and color $c_0$. There are two types of queries: 1. You are given an existing node $u$ and a color $c$. Let's denote the number of nodes in the tree before this query by $k$. Create a node with label $k+1$ and color $c$, and add i
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