Check if all 3 indices can be placed to respective correct indices in a single move
if ( arr [ arr [ arr [ i ] ] ] == i && arr [ arr [ i ] ] != i ) { int temp = arr [ arr [ i ] ] ; indices . push_back ( { i , arr [ i ] , arr [ arr [ i ] ] } ) ; swap ( arr [ i ] , arr [ arr [ i ] ] ) ; swap ( arr [ i ] , arr [ temp ] ) ; } }