Subtree Center
You are given a tree with $N$ nodes (numbered $1$ through $N$) and $Q$ queries (numbered $1$ through $Q$). For each valid $i$, in the $i$-th query, you are given $K_i$ nodes $x_1, x_2, \ldots, x_{K_i}$. Consider the smallest subtree which contains all of these nodes; you should find all centers of this subtree. A node is called a *center* of a tree if it lies in the middle of at least one longest
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