private static long [ ] dfs ( int item , int prev ) {
  long min = 0 , max = 0 ;
  for ( int elem : graph [ item ] ) {
    if ( elem == prev ) continue ;
    long [ ] next = dfs ( elem , item ) ;
    min = Math . min ( min , next [ 0 ] ) ;
    max = Math . max ( max , next [ 1 ] ) ;
  }
  long x = arr [ item ] + min + max ;
  if ( x > 0 ) min -= x ;
  else max -= x ;
  return new long [ ] {
    min , max };
  }
  
private static long [ ] dfs ( int item , int prev ) { long min = 0 , max = 0 ; for ( int elem : graph [ item ] ) { if ( elem == prev ) continue ; long [ ] next = dfs ( elem , item ) ; min = Math . min ( min , next [ 0 ] ) ; max = Math . max ( max , next [ 1 ] ) ; } long x = arr [ item ] + min + max ; if ( x > 0 ) min -= x ; else max -= x ; return new long [ ] { min , max } ; }
(method_declaration (modifiers) type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier) parameters: (formal_parameters (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)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (decimal_integer_literal)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier))) alternative: (expression_statement (assignment_expression left: (identifier) right: (identifier)))) (return_statement (array_creation_expression type: (integral_type) dimensions: (dimensions) value: (array_initializer (identifier) (identifier))))))