static int minCost ( int [ ] [ ] graph , int n ) {
  int cost1 = 0 , cost2 = 0 ;
  boolean [ ] start = new boolean [ n + 1 ] ;
  boolean [ ] end = new boolean [ n + 1 ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int a = graph [ i ] [ 0 ] ;
    int b = graph [ i ] [ 1 ] ;
    int c = graph [ i ] [ 2 ] ;
    if ( start [ a ] || end [ b ] ) {
      cost2 += c ;
      start [ b ] = true ;
      end [ a ] = true ;
    }
    else {
      cost1 += c ;
      start [ a ] = true ;
      end [ b ] = true ;
    }
  }
  return Math . min ( cost1 , cost2 ) ;
}

static int minCost ( int [ ] [ ] graph , int n ) { int cost1 = 0 , cost2 = 0 ; boolean [ ] start = new boolean [ n + 1 ] ; boolean [ ] end = new boolean [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { int a = graph [ i ] [ 0 ] ; int b = graph [ i ] [ 1 ] ; int c = graph [ i ] [ 2 ] ; if ( start [ a ] || end [ b ] ) { cost2 += c ; start [ b ] = true ; end [ a ] = true ; } else { cost1 += c ; start [ a ] = true ; end [ b ] = true ; } } return Math . min ( cost1 , cost2 ) ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) 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))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (binary_expression left: (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))))))) (return_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))))))