← All problemsSign in

Subham, Alisha and the tree

Tree is a connected acyclic graph .Subham has given a tree consisting of n vertices to Alisha. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed n/2. You need to help Alisha with the following problem. As Subham has Given a tree of size n, You can perform no more than one edge replacement. Ed

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