SMCMP- DSU approach not working?

I was trying to solve this question CodeChef: Practical coding for everyone using DSU. Here is a link to my submission VIy79B - Online C++0x Compiler & Debugging Tool - Ideone.com
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