Sample test case passes but others dont

I have done a simple dfs and size of adjlist is the no of children it has
for a node n adjlist[n].size() is no of children of parent.
and iterating thru neighbours of it, say a node v
adjlist[v].size()-1 will give number of children of that particular node.

The problem is a 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.

You can refer to the following code for better understanding:
https://ide.codingblocks.com/s/204947

Hope, this would help.
Give a like if you are satisfied.

I have done the loop the dfs for multiple components. Your code is too clumsy to decipher. can you write a simpler pseudocode? also it make no sense in storing another child array as we can get the same thing by size of adjacent list of particular node.