← All problemsSign in

B - Connect 3

You are given a tree consisting of $n$ vertices. The vertices are numbered from $1$ to $n$. Each vertex $i$ has a value $c_i$ associated with it, where $c_i \in \{1, 2, 3\}$. It is guaranteed that each value appears at least once. You can perform the following operation any number of times: - Choose two distinct vertices $i$ and $j$ ($1 \le i, j \le n$). - Swap the values $c_i$ and $c_j$. Your

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