# lock_pairs skips middle pair if it creates a cycle

I am doing `tideman` and I can't find the source of this error.below are my code=>

``````bool isCircle(int from,int edgevalue,int paircount){
for(int i=0;i<paircount;i++)
{
if(pairs[i].loser == from){
if(pairs[i].winner == edgevalue){
return true;
}

return isCircle(pairs[i].winner,edgevalue,paircount);
}
}
return false;
}

void lock_pairs(void)
{
// TODO
for(int i=0;i<pair_count;i++)
{
if(i<1)
{
locked[pairs[i].winner][pairs[i].loser]=true;
continue;
}

bool circle=isCircle(pairs[i].winner,pairs[i].loser,i);

if(circle){
locked[pairs[i].winner][pairs[i].loser]=false;
continue;
}

locked[pairs[i].winner][pairs[i].loser]=true;

}
return;
}
``````

I only got this error message=>

:( lock_pairs skips middle pair if it creates a cycle
lock_pairs did not correctly lock all non-cyclical pairs

• Again, use `locked`, not `pairs` in your recursive function. Edges that are not locked (because they would have created cycles, or are just not due yet) should have no influence on the check. – Blauelf Feb 5 at 9:39
• @Blauelf, Now I check the locked pair only right? I just loop with only `paircount`, that pair count comes from locked_pair`i` and that means I only checked the locked pair only right? – Loran Feb 5 at 10:07
• @Blauelf, If I understand what u said, this recursive function is only needed to check for locked pair only right? – Loran Feb 5 at 10:11
• @Blauelf, My idea is let say I have 3 pairs, first pair no need to check and second pair only need to check with first pair for whether circle or not and third pair will check first and second pair for circle. – Loran Feb 5 at 10:38
• Passing `i` would fix the "not due yet" part, but not the "were not added because of potential cycles" part. I would not use `pairs` in the recursive function at all. – Blauelf Feb 5 at 11:24