In the problem beautiful vertices, sample test case is passing . But getting WA for private testcases.
My solution:
problem:
https://hack.codingblocks.com/contests/c/925/782
Beautiful Vertices WA
@Devyendu-Shekhar-959527340852299
You need to count the no of vertices that have more children than their parents. The parents are to be found using DFS algo. You have not compared with the nodes with their parents but rather their neighbours which only works for the sample testcase but fails all other.
Kindly make the according changes in your code. Make an array or a map for marking the parents of the nodes ( parent[source] = source is the exception ). Find the parents of other nodes using DFS and then compare no of children of each node with no of children of its parent.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.