SMCMP- DSU approach not working?

I was trying to solve this question https://www.codechef.com/ALPAST01/problems/SMCMP using DSU. Here is a link to my submission https://ideone.com/VIy79B
This approach gives me WA and it would be great if anyone could help me

1 Like

@admin @ssjgz @l_returns @vijju123 It would be great if anyone of you could him.

1 Like
line 7 : return i=a[i]; 

Should be

return find(a,a[i]);            

Or

if(a[i]!=i)
    return i=a[i];

Should be

while(a[i]!=i)
      i=a[i];
4 Likes

Thank You @l_returns …found my mistake

1 Like