← All problemsSign in

Jack and John

There are two friends Jack and John, they work at the same company. After a hectic week at work, Jack and John decide to go on a fun weekend camping trip. As they were passing through a forest, they stumbled upon a unique tree of $N$ nodes. Vertices are numbered from $1 to N$. Each node of the tree is assigned a color (out of $C$ possible colors). Being bored, they decide to work together (for a

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