


import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
 import jax

 from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel





class   __a      (   unittest.TestCase				):
 def __init__(       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__=13    ,			lowerCAmelCase__=30    ,			lowerCAmelCase__=2    ,			lowerCAmelCase__=3    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=32    ,			lowerCAmelCase__=5    ,			lowerCAmelCase__=4    ,			lowerCAmelCase__=37    ,			lowerCAmelCase__="gelu"    ,			lowerCAmelCase__=0.1    ,			lowerCAmelCase__=0.1    ,			lowerCAmelCase__=10    ,			lowerCAmelCase__=0.0_2    ,			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       int        =       parent
        lowercase__:       str        =       batch_size
        lowercase__:       Tuple        =       image_size
        lowercase__:       Union[str, Any]        =       patch_size
        lowercase__:       int        =       num_channels
        lowercase__:       Tuple        =       is_training
        lowercase__:       Optional[Any]        =       use_labels
        lowercase__:       List[str]        =       hidden_size
        lowercase__:       Tuple        =       num_hidden_layers
        lowercase__:       str        =       num_attention_heads
        lowercase__:       List[str]        =       intermediate_size
        lowercase__:       Optional[int]        =       hidden_act
        lowercase__:       List[str]        =       hidden_dropout_prob
        lowercase__:       int        =       attention_probs_dropout_prob
        lowercase__:       List[Any]        =       type_sequence_label_size
        lowercase__:       Tuple        =       initializer_range

        # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
        lowercase__:       List[str]        =       (image_size // patch_size) ** 2
        lowercase__:       Optional[int]        =       num_patches + 1
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       str        =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

        lowercase__:       Optional[Any]        =       ViTConfig(
            image_size=self.image_size    ,			patch_size=self.patch_size    ,			num_channels=self.num_channels    ,			hidden_size=self.hidden_size    ,			num_hidden_layers=self.num_hidden_layers    ,			num_attention_heads=self.num_attention_heads    ,			intermediate_size=self.intermediate_size    ,			hidden_act=self.hidden_act    ,			hidden_dropout_prob=self.hidden_dropout_prob    ,			attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,			is_decoder=lowerCAmelCase__    ,			initializer_range=self.initializer_range    ,			)

        return config, pixel_values
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       int        =       FlaxViTModel(config=lowerCAmelCase__			)
        lowercase__:       Tuple        =       model(lowerCAmelCase__			)
        # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
        lowercase__:       Optional[Any]        =       (self.image_size, self.image_size)
        lowercase__:       List[str]        =       (self.patch_size, self.patch_size)
        lowercase__:       List[Any]        =       (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
        self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, num_patches + 1, self.hidden_size)			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       str        =       self.type_sequence_label_size
        lowercase__:       Dict        =       FlaxViTForImageClassification(config=lowerCAmelCase__			)
        lowercase__:       Any        =       model(lowerCAmelCase__			)
        self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.type_sequence_label_size)			)

        # test greyscale images
        lowercase__:       List[Any]        =       1
        lowercase__:       int        =       FlaxViTForImageClassification(lowerCAmelCase__			)

        lowercase__:       List[Any]        =       floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
        lowercase__:       List[Any]        =       model(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    str:




        '''simple docstring'''
        lowercase__:       int        =       self.prepare_config_and_inputs()
        (
            (
            lowercase__
        )      ,						(
            lowercase__
        )      ,						
        ):       int        =       config_and_inputs
        lowercase__:       Optional[Any]        =       {'pixel_values': pixel_values}
        return config, inputs_dict





@require_flax
class   __a      (   __UpperCamelCase	,	unittest.TestCase				):
 __lowercase			:							str       					=			(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    None:




        '''simple docstring'''
        lowercase__:       List[str]        =       FlaxViTModelTester(self			)
        lowercase__:       Any        =       ConfigTester(self    ,			config_class=lowerCAmelCase__    ,			has_text_modality=lowerCAmelCase__    ,			hidden_size=37			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        self.config_tester.run_common_tests()
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       Any        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       Any        =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__      ,						lowercase__:       Union[str, Any]        =       self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
               lowercase__:       str        =       model_class(lowerCAmelCase__			)
               lowercase__:       Dict        =       inspect.signature(model.__call__			)
               # signature.parameters is an OrderedDict => so arg_names order is deterministic
               lowercase__:       Optional[int]        =       [*signature.parameters.keys()]

               lowercase__:       int        =       ['pixel_values']
               self.assertListEqual(arg_names[:1]    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        lowercase__      ,						lowercase__:       Union[str, Any]        =       self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
               with self.subTest(model_class.__name__			):
                      lowercase__:       List[Any]        =       self._prepare_for_class(lowerCAmelCase__    ,			lowerCAmelCase__			)
                      lowercase__:       Tuple        =       model_class(lowerCAmelCase__			)

                      @jax.jit
                      def model_jitted(lowerCAmelCase__    ,			**lowerCAmelCase__			):
                             return model(pixel_values=lowerCAmelCase__    ,			**lowerCAmelCase__			)

                      with self.subTest('JIT Enabled'			):
                             lowercase__:       Tuple        =       model_jitted(**lowerCAmelCase__			).to_tuple()

                      with self.subTest('JIT Disabled'			):
                             with jax.disable_jit():
                                    lowercase__:       Dict        =       model_jitted(**lowerCAmelCase__			).to_tuple()

                      self.assertEqual(len(lowerCAmelCase__			)    ,			len(lowerCAmelCase__			)			)
                      for jitted_output, output in zip(lowerCAmelCase__    ,			lowerCAmelCase__			):
                             self.assertEqual(jitted_output.shape    ,			output.shape			)
 @slow
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        for model_class_name in self.all_model_classes:
               lowercase__:       Optional[int]        =       model_class_name.from_pretrained('google/vit-base-patch16-224'			)
               lowercase__:       List[Any]        =       model(np.ones((1, 3, 224, 224)			)			)
               self.assertIsNotNone(lowerCAmelCase__			)






from collections import deque
from math import floor
from random import random
from time import time





class   __a      :
 def __init__(       self			) ->    Dict:




        '''simple docstring'''
        lowercase__:       Dict        =       {}
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__=1			) ->    Optional[int]:




        '''simple docstring'''
        if self.graph.get(lowerCAmelCase__			):
               if self.graph[u].count([w, v]			) == 0:
                      self.graph[u].append([w, v]			)
        else:
               lowercase__:       int        =       [[w, v]]
        if not self.graph.get(lowerCAmelCase__			):
               lowercase__:       Union[str, Any]        =       []
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        return list(self.graph			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Optional[int]:




        '''simple docstring'''
        if self.graph.get(lowerCAmelCase__			):
               for _ in self.graph[u]:
                      if _[1] == v:
                             self.graph[u].remove(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2    ,			lowerCAmelCase__=-1			) ->    Union[str, Any]:




        '''simple docstring'''
        if s == d:
               return []
        lowercase__:       Tuple        =       []
        lowercase__:       Tuple        =       []
        if s == -2:
               lowercase__:       Any        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       Dict        =       s

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       Dict        =       s
                      for node in self.graph[s]:
                             if visited.count(node[1]			) < 1:
                                    if node[1] == d:
                                           visited.append(lowerCAmelCase__			)
                                           return visited
                                    else:
                                           stack.append(node[1]			)
                                           visited.append(node[1]			)
                                           lowercase__:       Union[str, Any]        =       node[1]
                                           break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       Optional[int]        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Dict        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return visited
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-1			) ->    List[str]:




        '''simple docstring'''
        if c == -1:
               lowercase__:       int        =       floor(random() * 10_000			) + 10
        for i in range(lowerCAmelCase__			):
               # every vertex has max 100 edges
               for _ in range(floor(random() * 102			) + 1			):
                      lowercase__:       str        =       floor(random() * c			) + 1
                      if n != i:
                             self.add_pair(lowerCAmelCase__    ,			lowerCAmelCase__    ,			1			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2			) ->    Dict:




        '''simple docstring'''
        lowercase__:       int        =       deque()
        lowercase__:       Dict        =       []
        if s == -2:
               lowercase__:       Optional[int]        =       list(self.graph			)[0]
        d.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        while d:
               lowercase__:       str        =       d.popleft()
               if len(self.graph[s]			) != 0:
                      for node in self.graph[s]:
                             if visited.count(node[1]			) < 1:
                                    d.append(node[1]			)
                                    visited.append(node[1]			)
        return visited
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    Dict:




        '''simple docstring'''
        lowercase__:       Tuple        =       0
        for x in self.graph:
               for y in self.graph[x]:
                      if y[1] == u:
                             count += 1
        return count
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    Union[str, Any]:




        '''simple docstring'''
        return len(self.graph[u]			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       Tuple        =       []
        lowercase__:       str        =       []
        if s == -2:
               lowercase__:       Dict        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       List[Any]        =       s
        lowercase__:       Any        =       []

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       List[str]        =       s
                      for node in self.graph[s]:
                             if visited.count(node[1]			) < 1:
                                    stack.append(node[1]			)
                                    visited.append(node[1]			)
                                    lowercase__:       Dict        =       node[1]
                                    break

            # check if all the children are visited
               if s == ss:
                      sorted_nodes.append(stack.pop()			)
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       int        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Optional[int]        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return sorted_nodes
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        lowercase__:       List[Any]        =       []
        lowercase__:       int        =       []
        lowercase__:       List[str]        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       Dict        =       -2
        lowercase__:       Union[str, Any]        =       []
        lowercase__:       List[str]        =       s
        lowercase__:       Dict        =       False
        lowercase__:       Union[str, Any]        =       set()

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       Any        =       s
                      for node in self.graph[s]:
                             if (
                                 visited.count(node[1]			) > 0
                                 and node[1] != parent
                                 and indirect_parents.count(node[1]			) > 0
                                 and not on_the_way_back
                             ):
                                    lowercase__:       List[Any]        =       len(lowerCAmelCase__			) - 1
                                    while len_stack >= 0:
                                           if stack[len_stack] == node[1]:
                                                  anticipating_nodes.add(node[1]			)
                                                  break
                                           else:
                                                  anticipating_nodes.add(stack[len_stack]			)
                                                  len_stack -= 1
                             if visited.count(node[1]			) < 1:
                                    stack.append(node[1]			)
                                    visited.append(node[1]			)
                                    lowercase__:       Union[str, Any]        =       node[1]
                                    break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      lowercase__:       Any        =       True
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       Optional[Any]        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Union[str, Any]        =       False
                      indirect_parents.append(lowerCAmelCase__			)
                      lowercase__:       int        =       s
                      lowercase__:       str        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return list(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       Any        =       []
        lowercase__:       int        =       []
        lowercase__:       Dict        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       Optional[int]        =       -2
        lowercase__:       List[Any]        =       []
        lowercase__:       List[str]        =       s
        lowercase__:       List[Any]        =       False
        lowercase__:       str        =       set()

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       Dict        =       s
                      for node in self.graph[s]:
                             if (
                                 visited.count(node[1]			) > 0
                                 and node[1] != parent
                                 and indirect_parents.count(node[1]			) > 0
                                 and not on_the_way_back
                             ):
                                    lowercase__:       Any        =       len(lowerCAmelCase__			) - 1
                                    while len_stack_minus_one >= 0:
                                           if stack[len_stack_minus_one] == node[1]:
                                                  anticipating_nodes.add(node[1]			)
                                                  break
                                           else:
                                                  return True
                             if visited.count(node[1]			) < 1:
                                    stack.append(node[1]			)
                                    visited.append(node[1]			)
                                    lowercase__:       List[Any]        =       node[1]
                                    break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      lowercase__:       Optional[Any]        =       True
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       Any        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Optional[Any]        =       False
                      indirect_parents.append(lowerCAmelCase__			)
                      lowercase__:       Dict        =       s
                      lowercase__:       Dict        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return False
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2    ,			lowerCAmelCase__=-1			) ->    Dict:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       time()
        self.dfs(lowerCAmelCase__    ,			lowerCAmelCase__			)
        lowercase__:       Optional[Any]        =       time()
        return end - begin
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2			) ->    List[str]:




        '''simple docstring'''
        lowercase__:       str        =       time()
        self.bfs(lowerCAmelCase__			)
        lowercase__:       List[str]        =       time()
        return end - begin





class   __a      :
 def __init__(       self			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       Dict        =       {}
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__=1			) ->    List[Any]:




        '''simple docstring'''
        # check if the u exists
        if self.graph.get(lowerCAmelCase__			):
               # if there already is a edge
               if self.graph[u].count([w, v]			) == 0:
                      self.graph[u].append([w, v]			)
        else:
               # if u does not exist
               lowercase__:       str        =       [[w, v]]
        # add the other way
        if self.graph.get(lowerCAmelCase__			):
               # if there already is a edge
               if self.graph[v].count([w, u]			) == 0:
                      self.graph[v].append([w, u]			)
        else:
               # if u does not exist
               lowercase__:       Union[str, Any]        =       [[w, u]]
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    str:




        '''simple docstring'''
        if self.graph.get(lowerCAmelCase__			):
               for _ in self.graph[u]:
                      if _[1] == v:
                             self.graph[u].remove(lowerCAmelCase__			)
        # the other way round
        if self.graph.get(lowerCAmelCase__			):
               for _ in self.graph[v]:
                      if _[1] == u:
                             self.graph[v].remove(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2    ,			lowerCAmelCase__=-1			) ->    List[str]:




        '''simple docstring'''
        if s == d:
               return []
        lowercase__:       str        =       []
        lowercase__:       int        =       []
        if s == -2:
               lowercase__:       Tuple        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       int        =       s

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       int        =       s
                      for node in self.graph[s]:
                             if visited.count(node[1]			) < 1:
                                    if node[1] == d:
                                           visited.append(lowerCAmelCase__			)
                                           return visited
                                    else:
                                           stack.append(node[1]			)
                                           visited.append(node[1]			)
                                           lowercase__:       List[Any]        =       node[1]
                                           break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       Union[str, Any]        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Optional[Any]        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return visited
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-1			) ->    Optional[Any]:




        '''simple docstring'''
        if c == -1:
               lowercase__:       Any        =       floor(random() * 10_000			) + 10
        for i in range(lowerCAmelCase__			):
               # every vertex has max 100 edges
               for _ in range(floor(random() * 102			) + 1			):
                      lowercase__:       Optional[Any]        =       floor(random() * c			) + 1
                      if n != i:
                             self.add_pair(lowerCAmelCase__    ,			lowerCAmelCase__    ,			1			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       str        =       deque()
        lowercase__:       List[Any]        =       []
        if s == -2:
               lowercase__:       str        =       list(self.graph			)[0]
        d.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        while d:
               lowercase__:       Union[str, Any]        =       d.popleft()
               if len(self.graph[s]			) != 0:
                      for node in self.graph[s]:
                             if visited.count(node[1]			) < 1:
                                    d.append(node[1]			)
                                    visited.append(node[1]			)
        return visited
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    List[Any]:




        '''simple docstring'''
        return len(self.graph[u]			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    str:




        '''simple docstring'''
        lowercase__:       str        =       []
        lowercase__:       Dict        =       []
        lowercase__:       Optional[int]        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       Dict        =       -2
        lowercase__:       Dict        =       []
        lowercase__:       List[Any]        =       s
        lowercase__:       Union[str, Any]        =       False
        lowercase__:       List[str]        =       set()

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       Optional[int]        =       s
                      for node in self.graph[s]:
                             if (
                                 visited.count(node[1]			) > 0
                                 and node[1] != parent
                                 and indirect_parents.count(node[1]			) > 0
                                 and not on_the_way_back
                             ):
                                    lowercase__:       Any        =       len(lowerCAmelCase__			) - 1
                                    while len_stack >= 0:
                                           if stack[len_stack] == node[1]:
                                                  anticipating_nodes.add(node[1]			)
                                                  break
                                           else:
                                                  anticipating_nodes.add(stack[len_stack]			)
                                                  len_stack -= 1
                             if visited.count(node[1]			) < 1:
                                    stack.append(node[1]			)
                                    visited.append(node[1]			)
                                    lowercase__:       List[str]        =       node[1]
                                    break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      lowercase__:       str        =       True
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       Dict        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       int        =       False
                      indirect_parents.append(lowerCAmelCase__			)
                      lowercase__:       Tuple        =       s
                      lowercase__:       List[Any]        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return list(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        lowercase__:       Tuple        =       []
        lowercase__:       Optional[int]        =       []
        lowercase__:       Optional[Any]        =       list(self.graph			)[0]
        stack.append(lowerCAmelCase__			)
        visited.append(lowerCAmelCase__			)
        lowercase__:       Tuple        =       -2
        lowercase__:       Any        =       []
        lowercase__:       int        =       s
        lowercase__:       Optional[int]        =       False
        lowercase__:       List[Any]        =       set()

        while True:
               # check if there is any non isolated nodes
               if len(self.graph[s]			) != 0:
                      lowercase__:       Optional[int]        =       s
                      for node in self.graph[s]:
                             if (
                                 visited.count(node[1]			) > 0
                                 and node[1] != parent
                                 and indirect_parents.count(node[1]			) > 0
                                 and not on_the_way_back
                             ):
                                    lowercase__:       Union[str, Any]        =       len(lowerCAmelCase__			) - 1
                                    while len_stack_minus_one >= 0:
                                           if stack[len_stack_minus_one] == node[1]:
                                                  anticipating_nodes.add(node[1]			)
                                                  break
                                           else:
                                                  return True
                             if visited.count(node[1]			) < 1:
                                    stack.append(node[1]			)
                                    visited.append(node[1]			)
                                    lowercase__:       Any        =       node[1]
                                    break

            # check if all the children are visited
               if s == ss:
                      stack.pop()
                      lowercase__:       List[str]        =       True
                      if len(lowerCAmelCase__			) != 0:
                             lowercase__:       List[str]        =       stack[len(lowerCAmelCase__			) - 1]
               else:
                      lowercase__:       Dict        =       False
                      indirect_parents.append(lowerCAmelCase__			)
                      lowercase__:       Optional[Any]        =       s
                      lowercase__:       Optional[int]        =       ss

               # check if se have reached the starting point
               if len(lowerCAmelCase__			) == 0:
                      return False
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        return list(self.graph			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2    ,			lowerCAmelCase__=-1			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       Dict        =       time()
        self.dfs(lowerCAmelCase__    ,			lowerCAmelCase__			)
        lowercase__:       List[Any]        =       time()
        return end - begin
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__=-2			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       str        =       time()
        self.bfs(lowerCAmelCase__			)
        lowercase__:       List[str]        =       time()
        return end - begin


