Pairing Graph Problem

https://ide.codingblocks.com/s/301732 This is my code
None of the test cases are passing except custom input test case.
Plz help!!!

@Bhawna everything is fine, just use long long int for ans to avoid overflow

Ya it worked…