Please help find the error

Hello, @goyalvivek,

Update your conditions inside is_cycle() function,

if(par[a] != par[b] || par[a]==-1 || par[b]==-1)
{
union_set(a, b, par, rank);
}

because initially for each i, par[i] == -1 and hence par[a]== par[b] == -1.
So, to avoid this error simpy check whether par[a] == -1 and par[b]==-1

got it, thanks 4 ur help

1 Like

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.