



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



class 						UpperCAmelCase_					:







							def __init__(     self):

														'''simple docstring'''

														_lowerCAmelCase  :							Tuple				     =					{}







							def      snake_case__   (     self,    __a,    __a,    __a=1):

														'''simple docstring'''

														if self.graph.get(__a):
																					if self.graph[u].count([w, v]) == 0:
																												self.graph[u].append([w, v])
														else:
																					_lowerCAmelCase  :							Optional[int]				     =					[[w, v]]
														if not self.graph.get(__a):
																					_lowerCAmelCase  :							Any				     =					[]







							def      snake_case__   (     self):

														'''simple docstring'''

														return list(self.graph)







							def      snake_case__   (     self,    __a,    __a):

														'''simple docstring'''

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







							def      snake_case__   (     self,    __a=-2,    __a=-1):

														'''simple docstring'''

														if s == d:
																					return []
														_lowerCAmelCase  :							Optional[int]				     =					[]
														_lowerCAmelCase  :							List[str]				     =					[]
														if s == -2:
																					_lowerCAmelCase  :							Tuple				     =					list(self.graph)[0]
														stack.append(__a)
														visited.append(__a)
														_lowerCAmelCase  :							str				     =					s

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

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

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







							def      snake_case__   (     self,    __a=-1):

														'''simple docstring'''

														if c == -1:
																					_lowerCAmelCase  :							Any				     =					floor(random() * 1_0000) + 10
														for i in range(__a):
																					# every vertex has max 100 edges
																					for _ in range(floor(random() * 102) + 1):
																												_lowerCAmelCase  :							Tuple				     =					floor(random() * c) + 1
																												if n != i:
																																			self.add_pair(__a,    __a,    1)







							def      snake_case__   (     self,    __a=-2):

														'''simple docstring'''

														_lowerCAmelCase  :							Any				     =					deque()
														_lowerCAmelCase  :							int				     =					[]
														if s == -2:
																					_lowerCAmelCase  :							Optional[Any]				     =					list(self.graph)[0]
														d.append(__a)
														visited.append(__a)
														while d:
																					_lowerCAmelCase  :							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      snake_case__   (     self,    __a):

														'''simple docstring'''

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







							def      snake_case__   (     self,    __a):

														'''simple docstring'''

														return len(self.graph[u])







							def      snake_case__   (     self,    __a=-2):

														'''simple docstring'''

														_lowerCAmelCase  :							Dict				     =					[]
														_lowerCAmelCase  :							Dict				     =					[]
														if s == -2:
																					_lowerCAmelCase  :							Tuple				     =					list(self.graph)[0]
														stack.append(__a)
														visited.append(__a)
														_lowerCAmelCase  :							List[str]				     =					s
														_lowerCAmelCase  :							str				     =					[]

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

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

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







							def      snake_case__   (     self):

														'''simple docstring'''

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

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

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

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







							def      snake_case__   (     self):

														'''simple docstring'''

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

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

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

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







							def      snake_case__   (     self,    __a=-2,    __a=-1):

														'''simple docstring'''

														_lowerCAmelCase  :							Tuple				     =					time()
														self.dfs(__a,    __a)
														_lowerCAmelCase  :							List[Any]				     =					time()
														return end - begin







							def      snake_case__   (     self,    __a=-2):

														'''simple docstring'''

														_lowerCAmelCase  :							int				     =					time()
														self.bfs(__a)
														_lowerCAmelCase  :							str				     =					time()
														return end - begin



class 						UpperCAmelCase_					:







							def __init__(     self):

														'''simple docstring'''

														_lowerCAmelCase  :							List[str]				     =					{}







							def      snake_case__   (     self,    __a,    __a,    __a=1):

														'''simple docstring'''

														if self.graph.get(__a):
																					# 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
																					_lowerCAmelCase  :							int				     =					[[w, v]]
														# add the other way
														if self.graph.get(__a):
																					# 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
																					_lowerCAmelCase  :							Any				     =					[[w, u]]







							def      snake_case__   (     self,    __a,    __a):

														'''simple docstring'''

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







							def      snake_case__   (     self,    __a=-2,    __a=-1):

														'''simple docstring'''

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

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

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

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







							def      snake_case__   (     self,    __a=-1):

														'''simple docstring'''

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







							def      snake_case__   (     self,    __a=-2):

														'''simple docstring'''

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

														'''simple docstring'''

														return len(self.graph[u])







							def      snake_case__   (     self):

														'''simple docstring'''

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

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

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

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







							def      snake_case__   (     self):

														'''simple docstring'''

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

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

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

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







							def      snake_case__   (     self):

														'''simple docstring'''

														return list(self.graph)







							def      snake_case__   (     self,    __a=-2,    __a=-1):

														'''simple docstring'''

														_lowerCAmelCase  :							List[Any]				     =					time()
														self.dfs(__a,    __a)
														_lowerCAmelCase  :							Union[str, Any]				     =					time()
														return end - begin







							def      snake_case__   (     self,    __a=-2):

														'''simple docstring'''

														_lowerCAmelCase  :							int				     =					time()
														self.bfs(__a)
														_lowerCAmelCase  :							Any				     =					time()
														return end - begin





from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case	=						logging.get_logger(__name__)

_snake_case	=						{
    "weiweishi/roc-bert-base-zh": "https://huggingface.co/weiweishi/roc-bert-base-zh/resolve/main/config.json",
}



class 						UpperCAmelCase_					( a):
							lowerCamelCase__         =	'roc_bert'







							def __init__(     self,    __a=3_0522,    __a=768,    __a=12,    __a=12,    __a=3072,    __a="gelu",    __a=0.1,    __a=0.1,    __a=512,    __a=2,    __a=0.02,    __a=1E-12,    __a=True,    __a=0,    __a="absolute",    __a=None,    __a=True,    __a=True,    __a=768,    __a=910,    __a=512,    __a=2_4858,    __a=True,    **__a,    ):

														'''simple docstring'''

														_lowerCAmelCase  :							Optional[Any]				     =					vocab_size
														_lowerCAmelCase  :							Optional[Any]				     =					max_position_embeddings
														_lowerCAmelCase  :							Union[str, Any]				     =					hidden_size
														_lowerCAmelCase  :							str				     =					num_hidden_layers
														_lowerCAmelCase  :							List[Any]				     =					num_attention_heads
														_lowerCAmelCase  :							int				     =					intermediate_size
														_lowerCAmelCase  :							Optional[int]				     =					hidden_act
														_lowerCAmelCase  :							Optional[Any]				     =					hidden_dropout_prob
														_lowerCAmelCase  :							Optional[Any]				     =					attention_probs_dropout_prob
														_lowerCAmelCase  :							Union[str, Any]				     =					initializer_range
														_lowerCAmelCase  :							Optional[Any]				     =					type_vocab_size
														_lowerCAmelCase  :							int				     =					layer_norm_eps
														_lowerCAmelCase  :							Union[str, Any]				     =					use_cache
														_lowerCAmelCase  :							Optional[int]				     =					enable_pronunciation
														_lowerCAmelCase  :							Dict				     =					enable_shape
														_lowerCAmelCase  :							Optional[Any]				     =					pronunciation_embed_dim
														_lowerCAmelCase  :							Any				     =					pronunciation_vocab_size
														_lowerCAmelCase  :							List[str]				     =					shape_embed_dim
														_lowerCAmelCase  :							int				     =					shape_vocab_size
														_lowerCAmelCase  :							Optional[int]				     =					concat_input
														_lowerCAmelCase  :							Dict				     =					position_embedding_type
														_lowerCAmelCase  :							Tuple				     =					classifier_dropout
														super().__init__(pad_token_id=__a,    **__a)
