private static int largestCircle ( ) {
  int N = in . nextInt ( ) ;
  int bff [ ] = new int [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    bff [ i ] = in . nextInt ( ) - 1 ;
  }
  int status [ ] = new int [ N ] ;
  int chainLength [ ] = new int [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    status [ i ] = - 2 ;
    chainLength [ i ] = 0 ;
  }
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    if ( bff [ bff [ i ] ] == i ) {
      status [ i ] = - 1 ;
    }
  }
  int maxLoopSize = 0 ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    if ( status [ i ] != - 1 ) {
      int current = bff [ i ] ;
      status [ i ] = i ;
      int steps = 1 ;
      boolean done = false ;
      while ( ! done ) {
        if ( current == i ) {
          if ( steps > maxLoopSize ) {
            maxLoopSize = steps ;
          }
          done = true ;
        }
        else if ( status [ current ] == i ) {
          done = true ;
        }
        else if ( status [ current ] == - 1 ) {
          if ( steps > chainLength [ current ] ) {
            chainLength [ current ] = steps ;
          }
          done = true ;
        }
        else {
          steps ++ ;
          status [ current ] = i ;
          current = bff [ current ] ;
        }
      }
    }
  }
  int frankenCircle = 0 ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    if ( status [ i ] == - 1 ) {
      frankenCircle += ( chainLength [ i ] + 1 ) ;
    }
  }
  return Math . max ( frankenCircle , maxLoopSize ) ;
}

private static int largestCircle ( ) { int N = in . nextInt ( ) ; int bff [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { bff [ i ] = in . nextInt ( ) - 1 ; } int status [ ] = new int [ N ] ; int chainLength [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { status [ i ] = - 2 ; chainLength [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( bff [ bff [ i ] ] == i ) { status [ i ] = - 1 ; } } int maxLoopSize = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] != - 1 ) { int current = bff [ i ] ; status [ i ] = i ; int steps = 1 ; boolean done = false ; while ( ! done ) { if ( current == i ) { if ( steps > maxLoopSize ) { maxLoopSize = steps ; } done = true ; } else if ( status [ current ] == i ) { done = true ; } else if ( status [ current ] == - 1 ) { if ( steps > chainLength [ current ] ) { chainLength [ current ] = steps ; } done = true ; } else { steps ++ ; status [ current ] = i ; current = bff [ current ] ; } } } } int frankenCircle = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] == - 1 ) { frankenCircle += ( chainLength [ i ] + 1 ) ; } } return Math . max ( frankenCircle , maxLoopSize ) ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (while_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (true)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (true)))) alternative: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))))))))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))