Beautiful vertices graph question

sir can u please check my code it gives ans 2 less than original ans please check of test cases https://ide.codingblocks.com/s/238151

https://ide.codingblocks.com/s/145247 You can refer this:
Not able to pass the sample test case
Approach has be explained.

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.