← All problemsSign in

Median on Tree

CodeChefRating 2358Open on judge ↗

For a given tree $T$ with $N$ nodes and a permutation $P$ of the integers $[1, N]$, we define %\text{score}(P)$ as follows: - Let $S_X$ denote the set of nodes that are either $X$ itself, or adjacent to $X$. - Let $A_X$ denote the median$^{\dagger}$ of the set $\{P_y: y \in S_X\}$. - $\text{score}(P) = $ number of integers $X$ ($1 \le X \le N$) such that $A_X = P_X$. For the given tree, find the

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