Beautiful vertices

Can I get some hint for this question

Hey! you can make a adjacency list of the graph and then start DFS on the graph. You can know the number of childeren of a vertex by accessing the size of the linked list for that vertex in the adjacency and you can keep marking in a boolean array true and false if that vertex is beautifull or not. And then count the number of beautiful nodes. DFS will work for this graph beacause every vertex would have atmost 1 parent as there are no self-loops and cycles in the graph.

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.