static LinkedList < Integer > helper ( int n ) {
  boolean [ ] vis = new boolean [ n + 1 ] ;
  LinkedList < Integer > ans = new LinkedList < > ( ) ;
  ans . add ( 1 ) ;
  ans . add ( graph [ 1 ] . get ( 0 ) ) ;
  vis [ 1 ] = true ;
  vis [ ans . peekLast ( ) ] = true ;
  boolean flag = true ;
  while ( flag ) {
    flag = false ;
    for ( int w : graph [ ans . peek ( ) ] ) {
      if ( ! vis [ w ] ) {
        ans . addFirst ( w ) ;
        vis [ w ] = true ;
        flag = true ;
        break ;
      }
    }
  }
  flag = true ;
  while ( flag ) {
    flag = false ;
    for ( int w : graph [ ans . peekLast ( ) ] ) {
      if ( ! vis [ w ] ) {
        ans . addLast ( w ) ;
        vis [ w ] = true ;
        flag = true ;
        break ;
      }
    }
  }
  return ans ;
}

static LinkedList < Integer > helper ( int n ) { boolean [ ] vis = new boolean [ n + 1 ] ; LinkedList < Integer > ans = new LinkedList < > ( ) ; ans . add ( 1 ) ; ans . add ( graph [ 1 ] . get ( 0 ) ) ; vis [ 1 ] = true ; vis [ ans . peekLast ( ) ] = true ; boolean flag = true ; while ( flag ) { flag = false ; for ( int w : graph [ ans . peek ( ) ] ) { if ( ! vis [ w ] ) { ans . addFirst ( w ) ; vis [ w ] = true ; flag = true ; break ; } } } flag = true ; while ( flag ) { flag = false ; for ( int w : graph [ ans . peekLast ( ) ] ) { if ( ! vis [ w ] ) { ans . addLast ( w ) ; vis [ w ] = true ; flag = true ; break ; } } } return ans ; }
(method_declaration (modifiers) type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (array_access array: (identifier) index: (decimal_integer_literal)) name: (identifier) arguments: (argument_list (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (true))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (while_statement condition: (parenthesized_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (true))) (break_statement))))))) (expression_statement (assignment_expression left: (identifier) right: (true))) (while_statement condition: (parenthesized_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (true))) (break_statement))))))) (return_statement (identifier))))