Blocks on a Tree
You have a tree$^{\dagger}$ with $N$ nodes. Every node can be labelled $0$ or $1$, and you can decide the label. However, there must be **exactly** $K$ nodes labelled $1$. Let $p(u, v)$ denote the sequence of **labels of nodes** on the unique shortest walk between nodes $u$ and $v$, and $f(u, v)$ denote the number of **blocks** in the sequence $p(u, v)$. A **block** is a maximal subarray such
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