Beautiful vertices getting TLE


how to reduce time compā€¦
i am getting TLE in both test cases

bro, itā€™s giving WA.

what youā€™re doing wrong is that youā€™re counting the parent node in the no_of_children of the child node

@aayushmathur05
actually i was taking directed graphā€¦
can u tell me why the cases are passed by making undirected graphā€¦since making an undirected graph how can we define parent and children???

@agarwalbhavya06
in the dfs helper function check first whether the ā€˜nbrā€™ is already visited or not, because of this it may be giving error.
Also take the edges as bidirected ones, because the input for every x,y can be in any order for eg 1,2 or 2,1 , so it should be sam ething for both the cases.

I have done the required changes in your code, have a look at it https://ide.codingblocks.com/s/247577
Mark this doubt as resolved if you got it now.

How did you determine the direction of edges in your directed graph from the given input?
You canā€™t do that.
The input just gives the two vertices which are connected. If ā€œaā€ and ā€œbā€ are connected then ā€œa bā€ and ā€œb aā€ mean that a is connected to b and b is connected to a. The input never specifies any direction of the edge.

@agarwalbhavya06
there is nothing said regarding the graph is directed, you can read it in the problem statement "two space separated integers X and Y denoting there is an edge between vertices X and Y.
So here you can take them as undirected ones.

ok got itā€¦
thanks @sanyamsinghalmnnit @aayushmathur05