Create a graph using given moves in arr [ ]
Vector < Integer > [ ] adj = new Vector [ 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 ) ;