i have submitted the code and there is TLE.
But can you please check if the logic of the code is correct or not and what is better method to avoid TLE.
Please see the code
@apoorvsingh27
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.