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