public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  int n = scanner . nextInt ( ) ;
  boolean [ ] visited = new boolean [ n + 1 ] ;
  int [ ] [ ] map = new int [ n + 1 ] [ 2 ] ;
  int [ ] [ ] cost = new int [ n + 1 ] [ 2 ] ;
  int sum = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int u = scanner . nextInt ( ) ;
    int v = scanner . nextInt ( ) ;
    int val = scanner . nextInt ( ) ;
    if ( map [ u ] [ 0 ] != 0 ) {
      map [ u ] [ 1 ] = v ;
      cost [ u ] [ 1 ] = val ;
    }
    else {
      map [ u ] [ 0 ] = v ;
      cost [ u ] [ 0 ] = val ;
    }
    if ( map [ v ] [ 0 ] != 0 ) {
      map [ v ] [ 1 ] = u ;
    }
    else {
      map [ v ] [ 0 ] = u ;
    }
    sum += val ;
  }
  int i = 1 ;
  int cnt = n ;
  int cursum = 0 ;
  visited [ i ] = true ;
  while ( cnt -- > 1 ) {
    if ( ! visited [ map [ i ] [ 0 ] ] ) {
      cursum += cost [ i ] [ 0 ] ;
      i = map [ i ] [ 0 ] ;
      visited [ i ] = true ;
    }
    else {
      cursum += cost [ i ] [ 1 ] ;
      i = map [ i ] [ 1 ] ;
      visited [ i ] = true ;
    }
  }
  visited [ 1 ] = false ;
  if ( ! visited [ map [ i ] [ 0 ] ] ) {
    cursum += cost [ i ] [ 0 ] ;
    i = map [ i ] [ 0 ] ;
    visited [ i ] = true ;
  }
  else {
    cursum += cost [ i ] [ 1 ] ;
    i = map [ i ] [ 1 ] ;
    visited [ i ] = true ;
  }
  System . out . print ( Math . min ( cursum , sum - cursum ) ) ;
}

public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; boolean [ ] visited = new boolean [ n + 1 ] ; int [ ] [ ] map = new int [ n + 1 ] [ 2 ] ; int [ ] [ ] cost = new int [ n + 1 ] [ 2 ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int u = scanner . nextInt ( ) ; int v = scanner . nextInt ( ) ; int val = scanner . nextInt ( ) ; if ( map [ u ] [ 0 ] != 0 ) { map [ u ] [ 1 ] = v ; cost [ u ] [ 1 ] = val ; } else { map [ u ] [ 0 ] = v ; cost [ u ] [ 0 ] = val ; } if ( map [ v ] [ 0 ] != 0 ) { map [ v ] [ 1 ] = u ; } else { map [ v ] [ 0 ] = u ; } sum += val ; } int i = 1 ; int cnt = n ; int cursum = 0 ; visited [ i ] = true ; while ( cnt -- > 1 ) { if ( ! visited [ map [ i ] [ 0 ] ] ) { cursum += cost [ i ] [ 0 ] ; i = map [ i ] [ 0 ] ; visited [ i ] = true ; } else { cursum += cost [ i ] [ 1 ] ; i = map [ i ] [ 1 ] ; visited [ i ] = true ; } } visited [ 1 ] = false ; if ( ! visited [ map [ i ] [ 0 ] ] ) { cursum += cost [ i ] [ 0 ] ; i = map [ i ] [ 0 ] ; visited [ i ] = true ; } else { cursum += cost [ i ] [ 1 ] ; i = map [ i ] [ 1 ] ; visited [ i ] = true ; } System . out . print ( Math . min ( cursum , sum - cursum ) ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (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: (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: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (identifier) right: (decimal_integer_literal))) dimensions: (dimensions_expr (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 (binary_expression left: (identifier) right: (decimal_integer_literal))) dimensions: (dimensions_expr (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 (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) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (false))) (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (identifier)))))))))