private static String solve ( ) {
  for ( int i = 0 ;
  i < defs . size ( ) ;
  i ++ ) {
    List < Integer > contained = new ArrayList < Integer > ( ) ;
    Deque < Integer > d = new ArrayDeque ( ) ;
    d . addAll ( defs . get ( i ) ) ;
    contained . addAll ( defs . get ( i ) ) ;
    contained . add ( i ) ;
    while ( ! d . isEmpty ( ) ) {
      int v = d . remove ( ) ;
      for ( int k : defs . get ( v ) ) {
        if ( contained . contains ( k ) ) return "Yes" ;
        d . add ( k ) ;
        contained . add ( k ) ;
      }
    }
  }
  return "No" ;
}

private static String solve ( ) { for ( int i = 0 ; i < defs . size ( ) ; i ++ ) { List < Integer > contained = new ArrayList < Integer > ( ) ; Deque < Integer > d = new ArrayDeque ( ) ; d . addAll ( defs . get ( i ) ) ; contained . addAll ( defs . get ( i ) ) ; contained . add ( i ) ; while ( ! d . isEmpty ( ) ) { int v = d . remove ( ) ; for ( int k : defs . get ( v ) ) { if ( contained . contains ( k ) ) return " Yes " ; d . add ( k ) ; contained . add ( k ) ; } } } return " No " ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (block (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 (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) body: (block (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) consequence: (return_statement (string_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))))) (return_statement (string_literal))))