There is segmentation fault in the code?

please help me in finding the mistake and please verify my logic for this question also

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.

refer this code https://ide.codingblocks.com/s/587882

ok but why my approach is not correct? :sweat_smile: :sweat_smile:

so firstly u are considering it as a directed graph… but its not directed… secondly u are just applying indegree concept bcoz u considered it directed graph… so whole soln went wrong

1 Like

ok sir got it, thank you

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.