Beautiful Vertices - Graph Theory

Problem - https://hack.codingblocks.com/contests/c/537/782
My code-https://ide.codingblocks.com/s/79027

I am taking a different approach. Instead of calculating afterwards the no of parents and children , I am creating a different type of adjacency list where I am storing the list of parents as well as list of children.
I simply take the size of the lists and compare them. If parentCount < childCount for any node , I update my counter variable and return the count.
Try taking a look at the print () to understand how I am storing the adjacency list.

My code works for the given sample case but fails both the testcases.

Please help.