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







class  UpperCamelCase__		:







	'''simple docstring'''





	def __init__(			self		):
					A__  :	int         =							{}





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__=1		):
					if self.graph.get(UpperCamelCase__		):
									if self.graph[u].count([w, v]		) == 0:
													self.graph[u].append([w, v]		)
					else:
									A__  :	Dict         =							[[w, v]]
					if not self.graph.get(UpperCamelCase__		):
									A__  :	str         =							[]





	def   __snake_case				(			self		):
					return list(self.graph		)





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__		):
					if self.graph.get(UpperCamelCase__		):
									for _ in self.graph[u]:
													if _[1] == v:
																	self.graph[u].remove(UpperCamelCase__		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2				,       UpperCamelCase__=-1		):
					if s == d:
									return []
					A__  :	Union[str, Any]         =							[]
					A__  :	int         =							[]
					if s == -2:
									A__  :	Union[str, Any]         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	str         =							s

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

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

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





	def   __snake_case				(			self				,       UpperCamelCase__=-1		):
					if c == -1:
									A__  :	List[str]         =							floor(random() * 1_0000		) + 10
					for i in range(UpperCamelCase__		):
									# every vertex has max 100 edges
									for _ in range(floor(random() * 102		) + 1		):
													A__  :	int         =							floor(random() * c		) + 1
													if n != i:
																	self.add_pair(UpperCamelCase__				,       UpperCamelCase__				,       1		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2		):
					A__  :	int         =							deque()
					A__  :	Tuple         =							[]
					if s == -2:
									A__  :	int         =							list(self.graph		)[0]
					d.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					while d:
									A__  :	Dict         =							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   __snake_case				(			self				,       UpperCamelCase__		):
					A__  :	int         =							0
					for x in self.graph:
									for y in self.graph[x]:
													if y[1] == u:
																	count += 1
					return count





	def   __snake_case				(			self				,       UpperCamelCase__		):
					return len(self.graph[u]		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2		):
					A__  :	Optional[Any]         =							[]
					A__  :	str         =							[]
					if s == -2:
									A__  :	str         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	Union[str, Any]         =							s
					A__  :	Tuple         =							[]

					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:
																					stack.append(node[1]		)
																					visited.append(node[1]		)
																					A__  :	Optional[Any]         =							node[1]
																					break

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

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





	def   __snake_case				(			self		):
					A__  :	int         =							[]
					A__  :	int         =							[]
					A__  :	Any         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	Any         =							-2
					A__  :	Dict         =							[]
					A__  :	Optional[Any]         =							s
					A__  :	Optional[Any]         =							False
					A__  :	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__  :	str         =							len(UpperCamelCase__		) - 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__  :	List[Any]         =							node[1]
																					break

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

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





	def   __snake_case				(			self		):
					A__  :	List[str]         =							[]
					A__  :	Dict         =							[]
					A__  :	Optional[int]         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	Any         =							-2
					A__  :	Tuple         =							[]
					A__  :	List[str]         =							s
					A__  :	Union[str, Any]         =							False
					A__  :	int         =							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(UpperCamelCase__		) - 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__  :	Tuple         =							node[1]
																					break

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

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





	def   __snake_case				(			self				,       UpperCamelCase__=-2				,       UpperCamelCase__=-1		):
					A__  :	int         =							time()
					self.dfs(UpperCamelCase__				,       UpperCamelCase__		)
					A__  :	Optional[int]         =							time()
					return end - begin





	def   __snake_case				(			self				,       UpperCamelCase__=-2		):
					A__  :	List[str]         =							time()
					self.bfs(UpperCamelCase__		)
					A__  :	List[str]         =							time()
					return end - begin







class  UpperCamelCase__		:







	'''simple docstring'''





	def __init__(			self		):
					A__  :	int         =							{}





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__				,       UpperCamelCase__=1		):
					# check if the u exists
					if self.graph.get(UpperCamelCase__		):
									# 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(UpperCamelCase__		):
									# 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__  :	Any         =							[[w, u]]





	def   __snake_case				(			self				,       UpperCamelCase__				,       UpperCamelCase__		):
					if self.graph.get(UpperCamelCase__		):
									for _ in self.graph[u]:
													if _[1] == v:
																	self.graph[u].remove(UpperCamelCase__		)
        # the other way round
					if self.graph.get(UpperCamelCase__		):
									for _ in self.graph[v]:
													if _[1] == u:
																	self.graph[v].remove(UpperCamelCase__		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2				,       UpperCamelCase__=-1		):
					if s == d:
									return []
					A__  :	Optional[Any]         =							[]
					A__  :	int         =							[]
					if s == -2:
									A__  :	List[Any]         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	Tuple         =							s

					while True:
									# check if there is any non isolated nodes
									if len(self.graph[s]		) != 0:
													A__  :	List[Any]         =							s
													for node in self.graph[s]:
																	if visited.count(node[1]		) < 1:
																					if node[1] == d:
																									visited.append(UpperCamelCase__		)
																									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(UpperCamelCase__		) != 0:
																	A__  :	List[str]         =							stack[len(UpperCamelCase__		) - 1]
									else:
													A__  :	str         =							ss

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





	def   __snake_case				(			self				,       UpperCamelCase__=-1		):
					if c == -1:
									A__  :	Dict         =							floor(random() * 1_0000		) + 10
					for i in range(UpperCamelCase__		):
									# every vertex has max 100 edges
									for _ in range(floor(random() * 102		) + 1		):
													A__  :	List[str]         =							floor(random() * c		) + 1
													if n != i:
																	self.add_pair(UpperCamelCase__				,       UpperCamelCase__				,       1		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2		):
					A__  :	List[str]         =							deque()
					A__  :	str         =							[]
					if s == -2:
									A__  :	str         =							list(self.graph		)[0]
					d.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					while d:
									A__  :	Dict         =							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   __snake_case				(			self				,       UpperCamelCase__		):
					return len(self.graph[u]		)





	def   __snake_case				(			self		):
					A__  :	List[str]         =							[]
					A__  :	Optional[int]         =							[]
					A__  :	Dict         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	List[Any]         =							-2
					A__  :	Dict         =							[]
					A__  :	str         =							s
					A__  :	str         =							False
					A__  :	Tuple         =							set()

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

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

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





	def   __snake_case				(			self		):
					A__  :	Any         =							[]
					A__  :	Any         =							[]
					A__  :	Optional[int]         =							list(self.graph		)[0]
					stack.append(UpperCamelCase__		)
					visited.append(UpperCamelCase__		)
					A__  :	List[Any]         =							-2
					A__  :	List[str]         =							[]
					A__  :	Optional[Any]         =							s
					A__  :	Optional[Any]         =							False
					A__  :	Optional[int]         =							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__  :	Any         =							len(UpperCamelCase__		) - 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__  :	Union[str, Any]         =							node[1]
																					break

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

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





	def   __snake_case				(			self		):
					return list(self.graph		)





	def   __snake_case				(			self				,       UpperCamelCase__=-2				,       UpperCamelCase__=-1		):
					A__  :	List[str]         =							time()
					self.dfs(UpperCamelCase__				,       UpperCamelCase__		)
					A__  :	Any         =							time()
					return end - begin





	def   __snake_case				(			self				,       UpperCamelCase__=-2		):
					A__  :	Union[str, Any]         =							time()
					self.bfs(UpperCamelCase__		)
					A__  :	Optional[int]         =							time()
					return end - begin

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_SCREAMING_SNAKE_CASE    :      int          =			{
    'configuration_bert': ['BERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'BertConfig', 'BertOnnxConfig'],
    'tokenization_bert': ['BasicTokenizer', 'BertTokenizer', 'WordpieceTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Optional[Any]          =			['BertTokenizerFast']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Union[str, Any]          =			[
					    'BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'BertForMaskedLM',
					    'BertForMultipleChoice',
					    'BertForNextSentencePrediction',
					    'BertForPreTraining',
					    'BertForQuestionAnswering',
					    'BertForSequenceClassification',
					    'BertForTokenClassification',
					    'BertLayer',
					    'BertLMHeadModel',
					    'BertModel',
					    'BertPreTrainedModel',
					    'load_tf_weights_in_bert',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Tuple          =			[
					    'TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFBertEmbeddings',
					    'TFBertForMaskedLM',
					    'TFBertForMultipleChoice',
					    'TFBertForNextSentencePrediction',
					    'TFBertForPreTraining',
					    'TFBertForQuestionAnswering',
					    'TFBertForSequenceClassification',
					    'TFBertForTokenClassification',
					    'TFBertLMHeadModel',
					    'TFBertMainLayer',
					    'TFBertModel',
					    'TFBertPreTrainedModel',
					]
try:
					if not is_tensorflow_text_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Dict          =			['TFBertTokenizer']

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Optional[int]          =			[
					    'FlaxBertForCausalLM',
					    'FlaxBertForMaskedLM',
					    'FlaxBertForMultipleChoice',
					    'FlaxBertForNextSentencePrediction',
					    'FlaxBertForPreTraining',
					    'FlaxBertForQuestionAnswering',
					    'FlaxBertForSequenceClassification',
					    'FlaxBertForTokenClassification',
					    'FlaxBertModel',
					    'FlaxBertPreTrainedModel',
					]

if TYPE_CHECKING:
					from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
					from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_fast import BertTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_bert import (
										    BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BertForMaskedLM,
										    BertForMultipleChoice,
										    BertForNextSentencePrediction,
										    BertForPreTraining,
										    BertForQuestionAnswering,
										    BertForSequenceClassification,
										    BertForTokenClassification,
										    BertLayer,
										    BertLMHeadModel,
										    BertModel,
										    BertPreTrainedModel,
										    load_tf_weights_in_bert,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_bert import (
										    TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFBertEmbeddings,
										    TFBertForMaskedLM,
										    TFBertForMultipleChoice,
										    TFBertForNextSentencePrediction,
										    TFBertForPreTraining,
										    TFBertForQuestionAnswering,
										    TFBertForSequenceClassification,
										    TFBertForTokenClassification,
										    TFBertLMHeadModel,
										    TFBertMainLayer,
										    TFBertModel,
										    TFBertPreTrainedModel,
										)

					try:
										if not is_tensorflow_text_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_tf import TFBertTokenizer

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_bert import (
										    FlaxBertForCausalLM,
										    FlaxBertForMaskedLM,
										    FlaxBertForMultipleChoice,
										    FlaxBertForNextSentencePrediction,
										    FlaxBertForPreTraining,
										    FlaxBertForQuestionAnswering,
										    FlaxBertForSequenceClassification,
										    FlaxBertForTokenClassification,
										    FlaxBertModel,
										    FlaxBertPreTrainedModel,
										)

else:
					import sys

					_SCREAMING_SNAKE_CASE    :      Union[str, Any]          =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)