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
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