Beautiful Vertices - some doubts

  1. Can Master Parent be a beautiful Vertex?? (I have assumed it is possible when childrens of Master Parent are greater than 1) - is this right??

  2. Can you give me a wrong test-case for my code if my above assumptions hold?

Code id = https://ide.codingblocks.com/s/180331

@ayushjain.iitg Master parent cannot be a beautiful vertex.
A node is considered a beautiful if the number of children of that node is greater than the number of children of its parent node.
Consider a test case:
5 4
1 2
1 3
3 4
3 5

Your Output:
3

Expected Output:
0. Here node 3 is not beautiful because node 3 has 2 children and its parent 1 also has 2 children.

Idea is to do DFS for each component. Store number of child for each node in a map. Also make a parent map and then check for the condition.
Refer this Not able to pass the sample test case

Hi, thanks for letting me know about the case where master parent cannot be part of my ans!
Yaa…I also knew that dfs could have solved my question, but even bfs could solve and so I took my approach and finally it gave me AC after tweaking my code a bit!
Thanks for the help.
I have updated my code at : https://ide.codingblocks.com/s/180331

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.