static int dfs ( ArrayList < Integer > list [ ] , int idx , int par ) {
  int min = 0 ;
  ArrayList < Integer > node = new ArrayList < > ( ) ;
  for ( int temp : list [ idx ] ) {
    if ( temp == par ) continue ;
    int child = dfs ( list , temp , idx ) ;
    node . add ( child ) ;
  }
  Collections . sort ( node ) ;
  for ( int temp : node ) {
    min = Math . max ( temp , min ) + 1 ;
  }
  return min ;
}

static int dfs ( ArrayList < Integer > list [ ] , int idx , int par ) { int min = 0 ; ArrayList < Integer > node = new ArrayList < > ( ) ; for ( int temp : list [ idx ] ) { if ( temp == par ) continue ; int child = dfs ( list , temp , idx ) ; node . add ( child ) ; } Collections . sort ( node ) ; for ( int temp : node ) { min = Math . max ( temp , min ) + 1 ; } return min ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (array_access array: (identifier) index: (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (continue_statement)) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))) right: (decimal_integer_literal)))))) (return_statement (identifier))))