Create a graph using given moves in [ ] arr
List < int > [ ] adj = new List < int > [ n ] ; for ( int i = 0 ; i < n ; i ++ ) if ( i != ( i + arr [ i ] + n ) % n && adj [ i ] != null ) adj [ i ] . Add ( ( i + arr [ i ] + n ) % n ) ;