Beautiful Vertices problem

step1 : calculating inDegree and outDegree of each vertex.
step2 : checking if(inDegree < outDegree)
BeautifulVertexCount++;
for each vertex except vertex having inDegree is zero.

is above logic contradict for any test cases ??

Hi @rajujnvgupta
This is the right logic to solve the problem. But Look for the master parent!.
Take the example in given sample test case, only 2 is considered as Beautiful vertex, not 1(though it has 0 parent and one child).

@Jun18APP0015
@Robin_rst
i implemented my above logic but code giving me wrong answer but test case passed.
what will be output for below test case

10 6
2 1
2 3
2 4
6 5
5 7
5 9
i think
ans will be 1