← All problemsSign in

Tree Distance Set

CodeChefRating 2475Open on judge ↗

For an undirected tree with $N$ nodes and $N-1$ edges, where each node is colored either red or blue, define two sets $S_1$ and $S_2$ as follows: - $S_1 = \{dis(u,v) \mid 1 \leq u \lt v \leq N\}$ - $S_2 = \{dis(u,v) \mid 1 \leq u \lt v \leq N, color_u \neq color_v\}$ , where $dis(u,v) = $ number of edges on the simple path between $u$ and $v$. **Note:** Sets $S_1$ and $S_2$ only contain **dist

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