




"""simple docstring"""

import argparse
import pickle

import numpy as np
import torch
from torch import nn

from transformers import ReformerConfig, ReformerModelWithLMHead
from transformers.utils import logging


logging.set_verbosity_info()

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase=None	):




 """simple docstring"""






 assert torch_layer.weight.shape == weight.shape, f"""{torch_layer} layer.weight does not match"""
 A_  :				str	   =		nn.Parameter(__lowerCAmelCase	)
 if bias is not None:
  assert torch_layer.bias.shape == bias.shape, f"""{torch_layer} layer.bias does not match"""
  A_  :				int	   =		nn.Parameter(__lowerCAmelCase	)

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




 """simple docstring"""






 A_  :				Tuple	   =		np.asarray(weights[0]	)
 A_  :				Union[str, Any]	   =		np.asarray(weights[1]	)
 A_  :				str	   =		np.asarray(weights[2]	)

 set_param(
     torch_layer.self_attention.query_key  ,      torch.tensor(__lowerCAmelCase	).transpose(1  ,      2	).contiguous().view(-1  ,      __lowerCAmelCase	)  ,      )
 set_param(
     torch_layer.self_attention.value  ,      torch.tensor(__lowerCAmelCase	).transpose(1  ,      2	).contiguous().view(-1  ,      __lowerCAmelCase	)  ,      )
 set_param(
     torch_layer.output.dense  ,      torch.tensor(__lowerCAmelCase	).view(-1  ,      __lowerCAmelCase	).contiguous().transpose(0  ,      1	)  ,      )

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




 """simple docstring"""






 A_  :				Optional[int]	   =		np.asarray(weights[0]	)
 A_  :				Dict	   =		np.asarray(weights[1]	)
 A_  :				str	   =		np.asarray(weights[2]	)
 A_  :				Union[str, Any]	   =		np.asarray(weights[3]	)

 set_param(
     torch_layer.self_attention.query  ,      torch.tensor(__lowerCAmelCase	).transpose(1  ,      2	).contiguous().view(-1  ,      __lowerCAmelCase	)  ,      )
 set_param(
     torch_layer.self_attention.key  ,      torch.tensor(__lowerCAmelCase	).transpose(1  ,      2	).contiguous().view(-1  ,      __lowerCAmelCase	)  ,      )
 set_param(
     torch_layer.self_attention.value  ,      torch.tensor(__lowerCAmelCase	).transpose(1  ,      2	).contiguous().view(-1  ,      __lowerCAmelCase	)  ,      )
 set_param(
     torch_layer.output.dense  ,      torch.tensor(__lowerCAmelCase	).view(-1  ,      __lowerCAmelCase	).contiguous().transpose(0  ,      1	)  ,      )

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




 """simple docstring"""






 A_  :				List[Any]	   =		weights[0][0][0]
 A_  :				Union[str, Any]	   =		np.asarray(layer_norm_a[0]	)
 A_  :				int	   =		np.asarray(layer_norm_a[1]	)
 set_param(
     torch_block.attention.layer_norm  ,      torch.tensor(__lowerCAmelCase	)  ,      torch.tensor(__lowerCAmelCase	)  ,      )

 # lsh weights + output
 A_  :				Optional[int]	   =		weights[0][1]
 if len(__lowerCAmelCase	) < 4:
  set_layer_weights_in_torch_lsh(__lowerCAmelCase  ,      torch_block.attention  ,      __lowerCAmelCase	)
 else:
  set_layer_weights_in_torch_local(__lowerCAmelCase  ,      torch_block.attention  ,      __lowerCAmelCase	)

 # intermediate weighs
 A_  :				str	   =		weights[2][0][1][2]

 # Chunked Feed Forward
 if len(__lowerCAmelCase	) == 4:
  A_  :				int	   =		intermediate_weights[2]

 # layernorm 2
 A_  :				Dict	   =		np.asarray(intermediate_weights[0][0]	)
 A_  :				Union[str, Any]	   =		np.asarray(intermediate_weights[0][1]	)
 set_param(
     torch_block.feed_forward.layer_norm  ,      torch.tensor(__lowerCAmelCase	)  ,      torch.tensor(__lowerCAmelCase	)  ,      )

 # intermediate dense
 A_  :				int	   =		np.asarray(intermediate_weights[1][0]	)
 A_  :				Union[str, Any]	   =		np.asarray(intermediate_weights[1][1]	)
 set_param(
     torch_block.feed_forward.dense.dense  ,      torch.tensor(__lowerCAmelCase	).transpose(0  ,      1	).contiguous()  ,      torch.tensor(__lowerCAmelCase	)  ,      )

 # intermediate out
 A_  :				Union[str, Any]	   =		np.asarray(intermediate_weights[4][0]	)
 A_  :				Optional[Any]	   =		np.asarray(intermediate_weights[4][1]	)
 set_param(
     torch_block.feed_forward.output.dense  ,      torch.tensor(__lowerCAmelCase	).transpose(0  ,      1	).contiguous()  ,      torch.tensor(__lowerCAmelCase	)  ,      )

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




 """simple docstring"""






 A_  :				List[str]	   =		torch_model.reformer

 # word embeds
 A_  :				List[Any]	   =		np.asarray(weights[1]	)
 set_param(
     torch_model_reformer.embeddings.word_embeddings  ,      torch.tensor(__lowerCAmelCase	)  ,      )

 if isinstance(weights[3]  ,      __lowerCAmelCase	):
  A_  :				Union[str, Any]	   =		torch_model_reformer.embeddings.position_embeddings
  for emb_idx in range(len(position_embeddings.weights	)	):
   A_  :				Dict	   =		np.asarray(weights[3][emb_idx][0]	)
   assert (
       position_embeddings.weights[emb_idx].shape == emb_weights.shape
   ), f"""{position_embeddings[emb_idx]} emb does not match"""
   A_  :				Any	   =		nn.Parameter(torch.tensor(__lowerCAmelCase	)	)

 A_  :				int	   =		weights[5]
 assert len(torch_model_reformer.encoder.layers	) * 4 == len(
     __lowerCAmelCase	), "HF and trax model do not have the same number of layers"
 for layer_idx, layer in enumerate(torch_model_reformer.encoder.layers	):
  A_  :				Union[str, Any]	   =		trax_layer_weights[4 * layer_idx : 4 * (layer_idx + 1)]
  set_block_weights_in_torch(__lowerCAmelCase  ,      __lowerCAmelCase  ,      __lowerCAmelCase	)

 # output layer norm
 A_  :				List[Any]	   =		np.asarray(weights[7][0]	)
 A_  :				Dict	   =		np.asarray(weights[7][1]	)
 set_param(
     torch_model_reformer.encoder.layer_norm  ,      torch.tensor(__lowerCAmelCase	)  ,      torch.tensor(__lowerCAmelCase	)  ,      )

 # output embeddings
 A_  :				List[Any]	   =		np.asarray(weights[9][0]	)
 A_  :				Any	   =		np.asarray(weights[9][1]	)
 set_param(
     torch_model.lm_head.decoder  ,      torch.tensor(__lowerCAmelCase	).transpose(0  ,      1	).contiguous()  ,      torch.tensor(__lowerCAmelCase	)  ,      )

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	):




 """simple docstring"""






 A_  :				str	   =		ReformerConfig.from_json_file(__lowerCAmelCase	)
 print(f"""Building PyTorch model from configuration: {config}"""	)
 A_  :				Dict	   =		ReformerModelWithLMHead(__lowerCAmelCase	)

 with open(__lowerCAmelCase  ,      '''rb'''	) as f:
  A_  :				Dict	   =		pickle.load(__lowerCAmelCase	)['''weights''']

 set_model_weights_in_torch(__lowerCAmelCase  ,      __lowerCAmelCase  ,      config.hidden_size	)

 # Save pytorch-model
 print(f"""Save PyTorch model to {pytorch_dump_path}"""	)
 torch.save(model.state_dict()  ,      __lowerCAmelCase	)


if __name__ == "__main__":
  _lowerCamelCase  :			Dict        =       argparse.ArgumentParser()
  # Required parameters
  parser.add_argument(
      '--trax_model_pkl_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
  )
  parser.add_argument(
      '--config_file',
      default=None,
      type=str,
      required=True,
      help=(
          'The config json file corresponding to the pre-trained Reformer model. \n'
          'This specifies the model architecture.'
      ),
  )
  parser.add_argument(
      '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
  )
  _lowerCamelCase  :			Optional[Any]        =       parser.parse_args()
  convert_trax_checkpoint_to_pytorch(args.trax_model_pkl_path, args.config_file, args.pytorch_dump_path)











"""simple docstring"""

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

class        lowercase      :







				def __init__(							self   :					Dict       ):



					"""simple docstring"""

					A_  :				Tuple	   =		{}







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					List[Any]      ,     _lowerCamelCase   :					Dict      ,     _lowerCamelCase   :					List[Any]=1       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						if self.graph[u].count([w, v]       ) == 0:
							self.graph[u].append([w, v]       )
					else:
						A_  :				int	   =		[[w, v]]
					if not self.graph.get(_lowerCamelCase       ):
						A_  :				List[Any]	   =		[]







				def 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					return list(self.graph       )







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					str      ,     _lowerCamelCase   :					Tuple       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						for _ in self.graph[u]:
							if _[1] == v:
								self.graph[u].remove(_lowerCamelCase       )







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Optional[int]=-2      ,     _lowerCamelCase   :					Tuple=-1       ):



					"""simple docstring"""

					if s == d:
						return []
					A_  :				Union[str, Any]	   =		[]
					A_  :				Optional[int]	   =		[]
					if s == -2:
						A_  :				int	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Tuple	   =		s

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Optional[Any]	   =		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]       )
										A_  :				Union[str, Any]	   =		node[1]
										break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							if len(_lowerCamelCase       ) != 0:
								A_  :				Optional[int]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				List[Any]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return visited







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					List[Any]=-1       ):



					"""simple docstring"""

					if c == -1:
						A_  :				List[Any]	   =		floor(random() * 1_00_00       ) + 10
					for i in range(_lowerCamelCase       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 1_02       ) + 1       ):
							A_  :				Tuple	   =		floor(random() * c       ) + 1
							if n != i:
								self.add_pair(_lowerCamelCase      ,     _lowerCamelCase      ,     1       )







				def 					a_  (							self   :					Optional[int]      ,     _lowerCamelCase   :					Union[str, Any]=-2       ):



					"""simple docstring"""

					A_  :				List[str]	   =		deque()
					A_  :				int	   =		[]
					if s == -2:
						A_  :				Any	   =		list(self.graph       )[0]
					d.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					while d:
						A_  :				List[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 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Tuple       ):



					"""simple docstring"""

					A_  :				List[Any]	   =		0
					for x in self.graph:
						for y in self.graph[x]:
							if y[1] == u:
								count += 1
					return count







				def 					a_  (							self   :					Any      ,     _lowerCamelCase   :					Optional[Any]       ):



					"""simple docstring"""

					return len(self.graph[u]       )







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Tuple=-2       ):



					"""simple docstring"""

					A_  :				int	   =		[]
					A_  :				Optional[Any]	   =		[]
					if s == -2:
						A_  :				List[str]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				str	   =		s
					A_  :				List[Any]	   =		[]

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

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

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return sorted_nodes







				def 					a_  (							self   :					Dict       ):



					"""simple docstring"""

					A_  :				str	   =		[]
					A_  :				Dict	   =		[]
					A_  :				Dict	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Any	   =		-2
					A_  :				List[str]	   =		[]
					A_  :				Dict	   =		s
					A_  :				Tuple	   =		False
					A_  :				List[str]	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				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
								):
									A_  :				Tuple	   =		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]       )
									A_  :				int	   =		node[1]
									break

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

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return list(_lowerCamelCase       )







				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					A_  :				Dict	   =		[]
					A_  :				Dict	   =		[]
					A_  :				Optional[Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Optional[Any]	   =		-2
					A_  :				List[str]	   =		[]
					A_  :				List[Any]	   =		s
					A_  :				int	   =		False
					A_  :				Any	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Union[str, 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
								):
									A_  :				Dict	   =		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]       )
									A_  :				Any	   =		node[1]
									break

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

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return False







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					Union[str, Any]=-2      ,     _lowerCamelCase   :					int=-1       ):



					"""simple docstring"""

					A_  :				int	   =		time()
					self.dfs(_lowerCamelCase      ,     _lowerCamelCase       )
					A_  :				int	   =		time()
					return end - begin







				def 					a_  (							self   :					Optional[Any]      ,     _lowerCamelCase   :					str=-2       ):



					"""simple docstring"""

					A_  :				int	   =		time()
					self.bfs(_lowerCamelCase       )
					A_  :				Union[str, Any]	   =		time()
					return end - begin

class        lowercase      :







				def __init__(							self   :					Any       ):



					"""simple docstring"""

					A_  :				Tuple	   =		{}







				def 					a_  (							self   :					List[Any]      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Optional[int]=1       ):



					"""simple docstring"""

					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
						A_  :				Union[str, Any]	   =		[[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
						A_  :				Tuple	   =		[[w, u]]







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Dict       ):



					"""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 					a_  (							self   :					Any      ,     _lowerCamelCase   :					str=-2      ,     _lowerCamelCase   :					int=-1       ):



					"""simple docstring"""

					if s == d:
						return []
					A_  :				Optional[Any]	   =		[]
					A_  :				List[Any]	   =		[]
					if s == -2:
						A_  :				Optional[int]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Union[str, Any]	   =		s

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Any	   =		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]       )
										A_  :				int	   =		node[1]
										break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							if len(_lowerCamelCase       ) != 0:
								A_  :				List[Any]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				str	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return visited







				def 					a_  (							self   :					Optional[Any]      ,     _lowerCamelCase   :					Union[str, Any]=-1       ):



					"""simple docstring"""

					if c == -1:
						A_  :				List[Any]	   =		floor(random() * 1_00_00       ) + 10
					for i in range(_lowerCamelCase       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 1_02       ) + 1       ):
							A_  :				List[str]	   =		floor(random() * c       ) + 1
							if n != i:
								self.add_pair(_lowerCamelCase      ,     _lowerCamelCase      ,     1       )







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					List[Any]=-2       ):



					"""simple docstring"""

					A_  :				Dict	   =		deque()
					A_  :				Tuple	   =		[]
					if s == -2:
						A_  :				List[str]	   =		list(self.graph       )[0]
					d.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					while d:
						A_  :				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 					a_  (							self   :					Any      ,     _lowerCamelCase   :					int       ):



					"""simple docstring"""

					return len(self.graph[u]       )







				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					A_  :				Dict	   =		[]
					A_  :				Optional[int]	   =		[]
					A_  :				Union[str, Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				str	   =		-2
					A_  :				int	   =		[]
					A_  :				Optional[Any]	   =		s
					A_  :				str	   =		False
					A_  :				int	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Tuple	   =		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
								):
									A_  :				Tuple	   =		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]       )
									A_  :				str	   =		node[1]
									break

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

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return list(_lowerCamelCase       )







				def 					a_  (							self   :					Union[str, Any]       ):



					"""simple docstring"""

					A_  :				List[str]	   =		[]
					A_  :				int	   =		[]
					A_  :				List[Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				int	   =		-2
					A_  :				Tuple	   =		[]
					A_  :				Any	   =		s
					A_  :				Tuple	   =		False
					A_  :				Union[str, Any]	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				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
								):
									A_  :				Optional[int]	   =		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]       )
									A_  :				Optional[Any]	   =		node[1]
									break

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

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return False







				def 					a_  (							self   :					Union[str, Any]       ):



					"""simple docstring"""

					return list(self.graph       )







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					Union[str, Any]=-2      ,     _lowerCamelCase   :					str=-1       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		time()
					self.dfs(_lowerCamelCase      ,     _lowerCamelCase       )
					A_  :				Union[str, Any]	   =		time()
					return end - begin







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					str=-2       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		time()
					self.bfs(_lowerCamelCase       )
					A_  :				List[str]	   =		time()
					return end - begin





