@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