Pairing Problem - Graphs

My code is passing 3/6 test cases. I have used DSU to tackle the problem
Here is the code: https://ide.codingblocks.com/s/237602