WA for all cases

logic seems right ,yet i am getiing WA
plesse correct the code

Hello @S19LPPP0159,

Which question is this?

https://hack.codingblocks.com/contests/c/917/782

Your code is failing for the testcases, which contains cycles and self loops.
Example:
5 7
2 1
1 3
3 2
1 4
1 5
5 4
5 6
Your Output:
0
Expected Output:
1

Solution:
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.

For better understanding, you can refer to the below mentioned code:

Hope, this would help.

The question mentioned “The graph has no cycles or self loops.”

I am sorry, i just read it.
Then you can follow bfs approach.
I will soon reply to you regarding the mistake that is causing wrong answer.

Thanks,Waiting For your resolution