I have done using set union approach but my code is giving 3 wrong answers.
Https://ide.codingblocks.com/s/207813 3 test cases not running
@Adarshrajpandey,
This is how I implemented it (here), try to do like this, correct pairs = total - wrong pairs seems a better way to do it
your code is not showing sir
only question is showing of hacker blocks
is the code link in the form as u have told sir
but still 2 test cases are coming to be wrong please tell sir
I have implemented correct ans=total -wrong ans
@Adarshrajpandey,
I don’t think you should use DSU by order/rank, use the DSU by size like I have used.
why sir??any reason??
@Adarshrajpandey,
Corrected code, here
Correction->
- Line 21:
if(x==y) return; - Line 14:
return parent[u];
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.