← All problemsSign in

Paired Tree

CodeChefRating 3463Open on judge ↗

You are given a tree containing $2N$ vertices and $2N-1$ undirected edges. Vertex $u$ has the color $A_u$. It is guaranteed that each color from $1$ to $N$ appears **exactly twice** in the tree. Process $Q$ queries of two type on this tree: - $1 \ \ u \ \ v$: Swap the colors on vertices $u$ and $v$, i.e, swap $A_u$ and $A_v$. - $2\ \ k$: Let $u$ and $v$ be the two vertices colored $k$. Sup

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