← All problemsSign in

Vasya and Little Bear

Given a colorful tree consisting of N nodes. Each node u has a color C(u) and a positive integer H(u). Vasya loves drawing and decides to connect nodes of same color with her drawing pencils. Being lazy, she first chooses two different nodes u and v and then decides to connect nodes v1 and v2 iff - They exist in the path from u to v - Both nodes have the same color ie C(v1) = C(v2) - They are

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