← All problemsSign in

Least Size

CodeChefRating 2540Open on judge ↗

You are given a tree with $N$ nodes where each node is numbered from $1$ to $N$. Suppose you root the tree at node $R$. Then, the score of a permutation $P$ of length $N$ is defined as the **size** of the set $S$ containing $\texttt{LCA}(P_i, P_{i+1})$ for all $1\leq i \lt N$. Find the **minimum** score of a permutation over all possible roots and all possible permutations of length $N$. You

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start