private static int dfs ( int v , ArrayList < Integer > [ ] graph ) {
  if ( graph [ v ] . isEmpty ( ) ) {
    return 1 ;
  }
  int [ ] tmp = new int [ graph [ v ] . size ( ) ] ;
  for ( int i = 0 ;
  i < tmp . length ;
  i ++ ) {
    int u = graph [ v ] . get ( i ) ;
    tmp [ i ] = dfs ( u , graph ) ;
  }
  Arrays . sort ( tmp ) ;
  int max = 0 ;
  for ( int t : tmp ) {
    if ( t <= max ) max ++ ;
    else max = t ;
  }
  max ++ ;
  return max ;
}

private static int dfs ( int v , ArrayList < Integer > [ ] graph ) { if ( graph [ v ] . isEmpty ( ) ) { return 1 ; } int [ ] tmp = new int [ graph [ v ] . size ( ) ] ; for ( int i = 0 ; i < tmp . length ; i ++ ) { int u = graph [ v ] . get ( i ) ; tmp [ i ] = dfs ( u , graph ) ; } Arrays . sort ( tmp ) ; int max = 0 ; for ( int t : tmp ) { if ( t <= max ) max ++ ; else max = t ; } max ++ ; return max ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (array_type element: (generic_type (type_identifier) (type_arguments (type_identifier))) dimensions: (dimensions)) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list))) consequence: (block (return_statement (decimal_integer_literal)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list)))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (array_access array: (identifier) index: (identifier)) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (update_expression (identifier))) alternative: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) (expression_statement (update_expression (identifier))) (return_statement (identifier))))