← All problemsSign in

Even Distances

CodeChefRating 2590Open on judge ↗

You are given a tree on $N$ vertices numbered $1$ to $N$, and a permutation $P$ of $\{1, 2, \ldots, N\}$. In one **operation** on a tree, you may: - Choose an edge of the tree and remove it, then - Add an edge between any two vertices. The graph must remain a tree after the operation. For a tree $G$, let $\text{dist}_G(u, v)$ denote the number of edges on the path between $u$ and $v$ in $G$. F

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