Minimum Ugliness
You are given a tree with $N$ nodes where the nodes are numbered from $1$ to $N$. The tree is rooted at node $1$. The shortest distance between two nodes $u$ and $v$ is the number of edges in the unique shortest path between $u$ and $v$ in the tree. Let it be denoted by $\text{dist}(u, v)$. You have $Q$ queries of the following type: For the $i$-th query, let $A_i$ be a set of $K_i$ nodes in th
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