


'''simple docstring'''


from typing import List, Optional, Union

import numpy as np

from ....audio_utils import mel_filter_bank, optimal_fft_length, spectrogram, window_function
from ....feature_extraction_sequence_utils import SequenceFeatureExtractor
from ....feature_extraction_utils import BatchFeature
from ....file_utils import PaddingStrategy, TensorType
from ....utils import logging


lowerCamelCase__					=   logging.get_logger(__name__)






class 		lowerCAmelCase__	(	UpperCAmelCase__		):
			lowerCAmelCase       :		List[Any]				      =   ["input_features", "attention_mask"]




			def __init__(						self     :   List[str]		,     lowerCamelCase__     :   Union[str, Any]=80		,     lowerCamelCase__     :   Dict=1_60_00		,     lowerCamelCase__     :   List[Any]=0.0		,     lowerCamelCase__     :   Tuple=10		,     lowerCamelCase__     :   str=25		,     lowerCamelCase__     :   int="hamming_window"		,     lowerCamelCase__     :   Union[str, Any]=3_2_7_6_8.0		,     lowerCamelCase__     :   List[str]=0.9_7		,     lowerCamelCase__     :   List[Any]=1.0		,     lowerCamelCase__     :   Dict=True		,     lowerCamelCase__     :   List[str]=True		,     lowerCamelCase__     :   Optional[Any]=False		,     **lowerCamelCase__     :   Any		,     )      ->Tuple:



					'''simple docstring'''







					super().__init__(feature_size=lowerCamelCase__		,     sampling_rate=lowerCamelCase__		,     padding_value=lowerCamelCase__		,     **lowerCamelCase__       )

					_UpperCAmelCase						:				Tuple	    =					feature_size
					_UpperCAmelCase						:				str	    =					sampling_rate
					_UpperCAmelCase						:				Union[str, Any]	    =					padding_value
					_UpperCAmelCase						:				int	    =					hop_length
					_UpperCAmelCase						:				Union[str, Any]	    =					win_length
					_UpperCAmelCase						:				int	    =					frame_signal_scale
					_UpperCAmelCase						:				Dict	    =					preemphasis_coeff
					_UpperCAmelCase						:				Tuple	    =					mel_floor
					_UpperCAmelCase						:				Any	    =					normalize_means
					_UpperCAmelCase						:				Optional[int]	    =					normalize_vars
					_UpperCAmelCase						:				Any	    =					win_function
					_UpperCAmelCase						:				List[str]	    =					return_attention_mask

					_UpperCAmelCase						:				int	    =					win_length * sampling_rate // 10_00
					_UpperCAmelCase						:				Dict	    =					hop_length * sampling_rate // 10_00

					_UpperCAmelCase						:				Optional[Any]	    =					optimal_fft_length(self.sample_size       )
					_UpperCAmelCase						:				Union[str, Any]	    =					(self.n_fft // 2) + 1




			def 							lowerCAmelCase__			(						self     :   str		,     lowerCamelCase__     :   np.array       )      ->np.ndarray:



					'''simple docstring'''







					if self.win_function == "hamming_window":
							_UpperCAmelCase						:				Dict	    =					window_function(window_length=self.sample_size		,     name=self.win_function		,     periodic=lowerCamelCase__       )
					else:
							_UpperCAmelCase						:				List[Any]	    =					window_function(window_length=self.sample_size		,     name=self.win_function       )

					_UpperCAmelCase						:				Any	    =					mel_filter_bank(
					    num_frequency_bins=self.n_freqs		,     num_mel_filters=self.feature_size		,     min_frequency=0.0		,     max_frequency=self.sampling_rate / 2.0		,     sampling_rate=self.sampling_rate		,     )

					_UpperCAmelCase						:				List[Any]	    =					spectrogram(
					    one_waveform * self.frame_signal_scale		,     window=lowerCamelCase__		,     frame_length=self.sample_size		,     hop_length=self.sample_stride		,     fft_length=self.n_fft		,     center=lowerCamelCase__		,     preemphasis=self.preemphasis_coeff		,     mel_filters=lowerCamelCase__		,     mel_floor=self.mel_floor		,     log_mel="log"		,     )
					return msfc_features.T




			def 							lowerCAmelCase__			(						self     :   str		,     lowerCamelCase__     :   Optional[int]		,     lowerCamelCase__     :   str		,     lowerCamelCase__     :   Any       )      ->Tuple:



					'''simple docstring'''







					if self.normalize_means:
							_UpperCAmelCase						:				Optional[Any]	    =					x[:input_length].mean(axis=0       )
							_UpperCAmelCase						:				List[Any]	    =					np.subtract(lowerCamelCase__		,     lowerCamelCase__       )
					if self.normalize_vars:
							_UpperCAmelCase						:				Dict	    =					x[:input_length].std(axis=0       )
							_UpperCAmelCase						:				List[Any]	    =					np.divide(lowerCamelCase__		,     lowerCamelCase__       )

					if input_length < x.shape[0]:
							_UpperCAmelCase						:				str	    =					padding_value

					# make sure array is in float32
					_UpperCAmelCase						:				int	    =					x.astype(np.floataa       )

					return x




			def 							lowerCAmelCase__			(						self     :   Dict		,     lowerCamelCase__     :   List[np.ndarray]		,     lowerCamelCase__     :   Optional[np.ndarray] = None       )      ->List[np.ndarray]:



					'''simple docstring'''







					_UpperCAmelCase						:				Any	    =					attention_mask.sum(-1       ) if attention_mask is not None else [x.shape[0] for x in input_features]
					return [self._normalize_one(lowerCamelCase__		,     lowerCamelCase__		,     self.padding_value       ) for x, n in zip(lowerCamelCase__		,     lowerCamelCase__       )]






			def __call__(						self     :   Tuple		,     lowerCamelCase__     :   Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]		,     lowerCamelCase__     :   Union[bool, str, PaddingStrategy] = False		,     lowerCamelCase__     :   Optional[int] = None		,     lowerCamelCase__     :   bool = False		,     lowerCamelCase__     :   Optional[int] = None		,     lowerCamelCase__     :   Optional[bool] = None		,     lowerCamelCase__     :   Optional[Union[str, TensorType]] = None		,     lowerCamelCase__     :   Optional[int] = None		,     **lowerCamelCase__     :   Optional[Any]		,     )      ->BatchFeature:



					'''simple docstring'''







					if sampling_rate is not None:
							if sampling_rate != self.sampling_rate:
									raise ValueError(
									    F"""The model corresponding to this feature extractor: {self} was trained using a sampling rate of"""
									    F""" {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with"""
									    F""" {self.sampling_rate} and not {sampling_rate}."""       )
					else:
							logger.warning(
							    "It is strongly recommended to pass the ``sampling_rate`` argument to this function. "
							    "Failing to do so can result in silent errors that might be hard to debug."       )

					_UpperCAmelCase						:				Tuple	    =					isinstance(lowerCamelCase__		,     np.ndarray       ) and len(raw_speech.shape       ) > 1
					if is_batched_numpy and len(raw_speech.shape       ) > 2:
							raise ValueError(F"""Only mono-channel audio is supported for input to {self}"""       )
					_UpperCAmelCase						:				str	    =					is_batched_numpy or (
					    isinstance(lowerCamelCase__		,     (list, tuple)       ) and (isinstance(raw_speech[0]		,     (np.ndarray, tuple, list)       ))
					)

					if is_batched:
							_UpperCAmelCase						:				int	    =					[np.asarray(lowerCamelCase__		,     dtype=np.floataa       ) for speech in raw_speech]
					elif not is_batched and not isinstance(lowerCamelCase__		,     np.ndarray       ):
							_UpperCAmelCase						:				str	    =					np.asarray(lowerCamelCase__		,     dtype=np.floataa       )
					elif isinstance(lowerCamelCase__		,     np.ndarray       ) and raw_speech.dtype is np.dtype(np.floataa       ):
							_UpperCAmelCase						:				int	    =					raw_speech.astype(np.floataa       )

					# always return batch
					if not is_batched:
							_UpperCAmelCase						:				int	    =					[raw_speech]

					# extract fbank features
					_UpperCAmelCase						:				Optional[Any]	    =					[self._extract_mfsc_features(lowerCamelCase__       ) for one_waveform in raw_speech]

					# convert into correct format for padding
					_UpperCAmelCase						:				List[str]	    =					BatchFeature({"input_features": features}       )

					_UpperCAmelCase						:				List[Any]	    =					self.pad(
					    lowerCamelCase__		,     padding=lowerCamelCase__		,     max_length=lowerCamelCase__		,     truncation=lowerCamelCase__		,     pad_to_multiple_of=lowerCamelCase__		,     return_attention_mask=lowerCamelCase__		,     **lowerCamelCase__		,     )
					# make sure list is in array format
					_UpperCAmelCase						:				Any	    =					padded_inputs.get("input_features"       )
					if isinstance(input_features[0]		,     lowerCamelCase__       ):
							_UpperCAmelCase						:				Optional[Any]	    =					[np.asarray(lowerCamelCase__		,     dtype=np.floataa       ) for feature in input_features]

					_UpperCAmelCase						:				Optional[int]	    =					padded_inputs.get("attention_mask"       )
					if attention_mask is not None:
							_UpperCAmelCase						:				Any	    =					[np.asarray(lowerCamelCase__		,     dtype=np.intaa       ) for array in attention_mask]

					if self.normalize_means or self.normalize_vars:
							_UpperCAmelCase						:				Dict	    =					(
							    np.array(lowerCamelCase__		,     dtype=np.intaa       )
							    if self._get_padding_strategies(lowerCamelCase__		,     max_length=lowerCamelCase__       ) is not PaddingStrategy.DO_NOT_PAD
							    and padding
							    else None
							)
							_UpperCAmelCase						:				Union[str, Any]	    =					self.normalize(
							    padded_inputs["input_features"]		,     attention_mask=lowerCamelCase__       )

					if return_tensors is not None:
							_UpperCAmelCase						:				Union[str, Any]	    =					padded_inputs.convert_to_tensors(lowerCamelCase__       )

					return padded_inputs







'''simple docstring'''


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






class 		lowerCAmelCase__	:




			def __init__(						self     :   Union[str, Any]       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				List[Any]	    =					{}




			def 							lowerCAmelCase__			(						self     :   Dict		,     lowerCamelCase__     :   Tuple		,     lowerCamelCase__     :   List[str]		,     lowerCamelCase__     :   int=1       )      ->Optional[Any]:



					'''simple docstring'''







					if self.graph.get(lowerCamelCase__       ):
							if self.graph[u].count([w, v]       ) == 0:
									self.graph[u].append([w, v]       )
					else:
							_UpperCAmelCase						:				Dict	    =					[[w, v]]
					if not self.graph.get(lowerCamelCase__       ):
							_UpperCAmelCase						:				str	    =					[]




			def 							lowerCAmelCase__			(						self     :   Any       )      ->Tuple:



					'''simple docstring'''







					return list(self.graph       )




			def 							lowerCAmelCase__			(						self     :   Tuple		,     lowerCamelCase__     :   Union[str, Any]		,     lowerCamelCase__     :   str       )      ->Any:



					'''simple docstring'''







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




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Optional[Any]=-2		,     lowerCamelCase__     :   Optional[int]=-1       )      ->int:



					'''simple docstring'''







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

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

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

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




			def 							lowerCAmelCase__			(						self     :   List[Any]		,     lowerCamelCase__     :   Any=-1       )      ->str:



					'''simple docstring'''







					if c == -1:
							_UpperCAmelCase						:				str	    =					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       ):
									_UpperCAmelCase						:				Tuple	    =					floor(random() * c       ) + 1
									if n != i:
											self.add_pair(lowerCamelCase__		,     lowerCamelCase__		,     1       )




			def 							lowerCAmelCase__			(						self     :   Any		,     lowerCamelCase__     :   Union[str, Any]=-2       )      ->Union[str, Any]:



					'''simple docstring'''







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



					'''simple docstring'''







					_UpperCAmelCase						:				Dict	    =					0
					for x in self.graph:
							for y in self.graph[x]:
									if y[1] == u:
											count += 1
					return count




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Union[str, Any]       )      ->int:



					'''simple docstring'''







					return len(self.graph[u]       )




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Any=-2       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[Any]	    =					[]
					_UpperCAmelCase						:				List[str]	    =					[]
					if s == -2:
							_UpperCAmelCase						:				str	    =					list(self.graph       )[0]
					stack.append(lowerCamelCase__       )
					visited.append(lowerCamelCase__       )
					_UpperCAmelCase						:				List[Any]	    =					s
					_UpperCAmelCase						:				Tuple	    =					[]

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

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

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




			def 							lowerCAmelCase__			(						self     :   Union[str, Any]       )      ->Optional[Any]:



					'''simple docstring'''







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

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

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

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




			def 							lowerCAmelCase__			(						self     :   int       )      ->Optional[int]:



					'''simple docstring'''







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

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

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

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




			def 							lowerCAmelCase__			(						self     :   str		,     lowerCamelCase__     :   Tuple=-2		,     lowerCamelCase__     :   Union[str, Any]=-1       )      ->Any:



					'''simple docstring'''







					_UpperCAmelCase						:				Dict	    =					time()
					self.dfs(lowerCamelCase__		,     lowerCamelCase__       )
					_UpperCAmelCase						:				Tuple	    =					time()
					return end - begin






			def 							lowerCAmelCase__			(						self     :   List[Any]		,     lowerCamelCase__     :   Dict=-2       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[Any]	    =					time()
					self.bfs(lowerCamelCase__       )
					_UpperCAmelCase						:				Tuple	    =					time()
					return end - begin






class 		lowerCAmelCase__	:




			def __init__(						self     :   Tuple       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase						:				Any	    =					{}




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   List[str]		,     lowerCamelCase__     :   str		,     lowerCamelCase__     :   Tuple=1       )      ->int:



					'''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
							_UpperCAmelCase						:				Dict	    =					[[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
							_UpperCAmelCase						:				Tuple	    =					[[w, u]]




			def 							lowerCAmelCase__			(						self     :   Dict		,     lowerCamelCase__     :   Any		,     lowerCamelCase__     :   Optional[Any]       )      ->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 							lowerCAmelCase__			(						self     :   List[str]		,     lowerCamelCase__     :   List[str]=-2		,     lowerCamelCase__     :   List[str]=-1       )      ->List[Any]:



					'''simple docstring'''







					if s == d:
							return []
					_UpperCAmelCase						:				List[Any]	    =					[]
					_UpperCAmelCase						:				List[Any]	    =					[]
					if s == -2:
							_UpperCAmelCase						:				List[Any]	    =					list(self.graph       )[0]
					stack.append(lowerCamelCase__       )
					visited.append(lowerCamelCase__       )
					_UpperCAmelCase						:				List[Any]	    =					s

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

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

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




			def 							lowerCAmelCase__			(						self     :   Any		,     lowerCamelCase__     :   Dict=-1       )      ->str:



					'''simple docstring'''







					if c == -1:
							_UpperCAmelCase						:				str	    =					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       ):
									_UpperCAmelCase						:				str	    =					floor(random() * c       ) + 1
									if n != i:
											self.add_pair(lowerCamelCase__		,     lowerCamelCase__		,     1       )




			def 							lowerCAmelCase__			(						self     :   str		,     lowerCamelCase__     :   Union[str, Any]=-2       )      ->Any:



					'''simple docstring'''







					_UpperCAmelCase						:				str	    =					deque()
					_UpperCAmelCase						:				Optional[int]	    =					[]
					if s == -2:
							_UpperCAmelCase						:				Union[str, Any]	    =					list(self.graph       )[0]
					d.append(lowerCamelCase__       )
					visited.append(lowerCamelCase__       )
					while d:
							_UpperCAmelCase						:				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 							lowerCAmelCase__			(						self     :   Union[str, Any]		,     lowerCamelCase__     :   Dict       )      ->Optional[Any]:



					'''simple docstring'''







					return len(self.graph[u]       )




			def 							lowerCAmelCase__			(						self     :   str       )      ->Any:



					'''simple docstring'''







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

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

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

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




			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->Dict:



					'''simple docstring'''







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

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

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

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




			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->int:



					'''simple docstring'''







					return list(self.graph       )




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Dict=-2		,     lowerCamelCase__     :   Dict=-1       )      ->List[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[Any]	    =					time()
					self.dfs(lowerCamelCase__		,     lowerCamelCase__       )
					_UpperCAmelCase						:				int	    =					time()
					return end - begin






			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Any=-2       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[Any]	    =					time()
					self.bfs(lowerCamelCase__       )
					_UpperCAmelCase						:				Any	    =					time()
					return end - begin



