Approach for the Question

I am facing wrong answer error. Kindly have a look at my approach :
I introduced 2 more variables in the VERTEX class viz nop ( number of parent ) and noc ( number of children ).
Secondly , I assumed from the given question , that the 1st input of every line is the Parent and the 2nd input in the same line is for its child.
Accordingly I changed the addVertex( ) function by telling when the parent is input ( at true ) and when the child is input ( at false ).
On that basis I update the value of noc and nop.
After that I used these values in my BeautifulVertices Function and checked the condition given in the question.

hi @mananaroramail
The problem is simple implementation of DFS while maintaining a count of children of the vertices visited. Let u be a vertex and v be its child. Then, check if children[v]>children[u].This way, check for each vertex while traversing the graph in DFS. One important thing to note that actually there are many trees in the input(a graph with no cycles and self loops is a tree). That means , you have to apply DFS for each of these trees.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.