
"""simple docstring"""


import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEmbeddings,
    BertLayer,
    BertPooler,
    BertPreTrainedModel,
)






def       _snake_case				(		snake_case__   :     Optional[int]     ):
	A						   =   torch.exp(__snake_case     )
	A						   =   torch.sum(__snake_case	,      dim=1     )  # sum of exp(x_i)
	A						   =   torch.sum(x * exp_x	,      dim=1     )  # sum of x_i * exp(x_i)
	return torch.log(__snake_case     ) - B / A







class 				lowerCAmelCase_				(      nn.Module    ):



						'''simple docstring'''


						def __init__( self     :      List[Any]  ,A_     :      Dict      )     ->   List[Any]:
							super().__init__()
							A						   =   config.output_attentions
							A						   =   config.output_hidden_states
							A						   =   nn.ModuleList([BertLayer(__lowerCAmelCase      ) for _ in range(config.num_hidden_layers      )]      )
							A						   =   nn.ModuleList([BertHighway(__lowerCAmelCase      ) for _ in range(config.num_hidden_layers      )]      )

							A						   =   [-1 for _ in range(config.num_hidden_layers      )]


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple  ,A_     :      Optional[Any]      )     ->   Optional[Any]:







							if (type(__lowerCAmelCase      ) is float) or (type(__lowerCAmelCase      ) is int):
								for i in range(len(self.early_exit_entropy      )      ):
									A						   =   x
							else:
								A						   =   x


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      List[str]      )     ->   Union[str, Any]:
							A						   =   pooler.state_dict()
							for highway in self.highway:
								for name, param in highway.pooler.state_dict().items():
									param.copy_(loaded_model[name]      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Optional[int]  ,A_     :      List[Any]=None  ,A_     :      List[Any]=None  ,A_     :      Dict=None  ,A_     :      List[str]=None  ,)     ->   Tuple:
							A						   =   ()
							A						   =   ()
							A						   =   ()
							for i, layer_module in enumerate(self.layer      ):
								if self.output_hidden_states:
									A						   =   all_hidden_states + (hidden_states,)

								A						   =   layer_module(
								    __lowerCAmelCase  ,__lowerCAmelCase  ,head_mask[i]  ,__lowerCAmelCase  ,__lowerCAmelCase      )
								A						   =   layer_outputs[0]

								if self.output_attentions:
									A						   =   all_attentions + (layer_outputs[1],)

								A						   =   (hidden_states,)
								if self.output_hidden_states:
									A						   =   current_outputs + (all_hidden_states,)
								if self.output_attentions:
									A						   =   current_outputs + (all_attentions,)

								A						   =   self.highway[i](__lowerCAmelCase      )
								# logits, pooled_output

								if not self.training:
									A						   =   highway_exit[0]
									A						   =   entropy(__lowerCAmelCase      )
									A						   =   highway_exit + (highway_entropy,)  # logits, hidden_states(?), entropy
									A						   =   all_highway_exits + (highway_exit,)

									if highway_entropy < self.early_exit_entropy[i]:
										A						   =   (highway_logits,) + current_outputs[1:] + (all_highway_exits,)
										raise HighwayException(__lowerCAmelCase  ,i + 1      )
								else:
									A						   =   all_highway_exits + (highway_exit,)

        # Add last layer
							if self.output_hidden_states:
								A						   =   all_hidden_states + (hidden_states,)

							A						   =   (hidden_states,)
							if self.output_hidden_states:
								A						   =   outputs + (all_hidden_states,)
							if self.output_attentions:
								A						   =   outputs + (all_attentions,)

							A						   =   outputs + (all_highway_exits,)
							return outputs  # last-layer hidden state, (all hidden states), (all attentions), all highway exits







@add_start_docstrings(
    '''The Bert Model transformer with early exiting (DeeBERT). '''		,					_lowercase		,					)
class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						def __init__( self     :      Optional[int]  ,A_     :      Any      )     ->   Tuple:
							super().__init__(__lowerCAmelCase      )
							A						   =   config

							A						   =   BertEmbeddings(__lowerCAmelCase      )
							A						   =   DeeBertEncoder(__lowerCAmelCase      )
							A						   =   BertPooler(__lowerCAmelCase      )

							self.init_weights()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Tuple:
							self.encoder.init_highway_pooler(self.pooler      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   List[Any]:
							return self.embeddings.word_embeddings


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]  ,A_     :      Tuple      )     ->   Tuple:
							A						   =   value


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      int      )     ->   List[str]:







							for layer, heads in heads_to_prune.items():
								self.encoder.layer[layer].attention.prune_heads(__lowerCAmelCase      )




						@add_start_docstrings_to_model_forward(__lowerCAmelCase      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      Optional[int]=None  ,A_     :      str=None  ,A_     :      Dict=None  ,A_     :      str=None  ,A_     :      Optional[int]=None  ,A_     :      int=None  ,A_     :      Optional[Any]=None  ,A_     :      Dict=None  ,)     ->   Dict:







							if input_ids is not None and inputs_embeds is not None:
								raise ValueError('You cannot specify both input_ids and inputs_embeds at the same time'      )
							elif input_ids is not None:
								A						   =   input_ids.size()
							elif inputs_embeds is not None:
								A						   =   inputs_embeds.size()[:-1]
							else:
								raise ValueError('You have to specify either input_ids or inputs_embeds'      )

							A						   =   input_ids.device if input_ids is not None else inputs_embeds.device

							if attention_mask is None:
								A						   =   torch.ones(__lowerCAmelCase  ,device=__lowerCAmelCase      )
							if encoder_attention_mask is None:
								A						   =   torch.ones(__lowerCAmelCase  ,device=__lowerCAmelCase      )
							if token_type_ids is None:
								A						   =   torch.zeros(__lowerCAmelCase  ,dtype=torch.long  ,device=__lowerCAmelCase      )

							# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
							# ourselves in which case we just need to make it broadcastable to all heads.
							A						   =   self.get_extended_attention_mask(__lowerCAmelCase  ,__lowerCAmelCase  ,__lowerCAmelCase      )

							# If a 2D ou 3D attention mask is provided for the cross-attention
							# we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
							if encoder_attention_mask.dim() == 3:
								A						   =   encoder_attention_mask[:, None, :, :]
							if encoder_attention_mask.dim() == 2:
								A						   =   encoder_attention_mask[:, None, None, :]

							A						   =   encoder_extended_attention_mask.to(
							    dtype=next(self.parameters()      ).dtype      )  # fp16 compatibility
							A						   =   (1.0 - encoder_extended_attention_mask) * -1_0000.0

							# Prepare head mask if needed
							# 1.0 in head_mask indicate we keep the head
							# attention_probs has shape bsz x n_heads x N x N
							# input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
							# and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
							A						   =   self.get_head_mask(__lowerCAmelCase  ,self.config.num_hidden_layers      )

							A						   =   self.embeddings(
							    input_ids=__lowerCAmelCase  ,position_ids=__lowerCAmelCase  ,token_type_ids=__lowerCAmelCase  ,inputs_embeds=__lowerCAmelCase      )
							A						   =   self.encoder(
							    __lowerCAmelCase  ,attention_mask=__lowerCAmelCase  ,head_mask=__lowerCAmelCase  ,encoder_hidden_states=__lowerCAmelCase  ,encoder_attention_mask=__lowerCAmelCase  ,)
							A						   =   encoder_outputs[0]
							A						   =   self.pooler(__lowerCAmelCase      )

							A						   =   (
							    sequence_output,
							    pooled_output,
							) + encoder_outputs[
							    1:
							]  # add hidden_states and attentions if they are here
							return outputs  # sequence_output, pooled_output, (hidden_states), (attentions), highway exits







class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						def __init__( self     :      Dict  ,A_     :      List[Any]  ,A_     :      Dict      )     ->   List[Any]:
							A						   =   message
							A						   =   exit_layer  # start from 1!







class 				lowerCAmelCase_				(      nn.Module    ):



						'''simple docstring'''


						def __init__( self     :      Any  ,A_     :      Optional[int]      )     ->   str:
							super().__init__()
							A						   =   BertPooler(__lowerCAmelCase      )
							A						   =   nn.Dropout(config.hidden_dropout_prob      )
							A						   =   nn.Linear(config.hidden_size  ,config.num_labels      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple  ,A_     :      Optional[int]      )     ->   Union[str, Any]:
							A						   =   encoder_outputs[0]
							A						   =   self.pooler(__lowerCAmelCase      )
							# "return" pooler_output

							# BertModel
							A						   =   (pooler_input, pooler_output) + encoder_outputs[1:]
							# "return" bmodel_output

							# Dropout and classification
							A						   =   bmodel_output[1]

							A						   =   self.dropout(__lowerCAmelCase      )
							A						   =   self.classifier(__lowerCAmelCase      )

							return logits, pooled_output







@add_start_docstrings(
    '''Bert Model (with early exiting - DeeBERT) with a classifier on top,
    also takes care of multi-layer training. '''		,					_lowercase		,					)
class 				lowerCAmelCase_				(      _lowercase    ):



						'''simple docstring'''


						def __init__( self     :      Union[str, Any]  ,A_     :      Any      )     ->   List[Any]:
							super().__init__(__lowerCAmelCase      )
							A						   =   config.num_labels
							A						   =   config.num_hidden_layers

							A						   =   DeeBertModel(__lowerCAmelCase      )
							A						   =   nn.Dropout(config.hidden_dropout_prob      )
							A						   =   nn.Linear(config.hidden_size  ,self.config.num_labels      )

							self.init_weights()




						@add_start_docstrings_to_model_forward(__lowerCAmelCase      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      Optional[int]=None  ,A_     :      Any=None  ,A_     :      str=None  ,A_     :      str=None  ,A_     :      Any=None  ,A_     :      int=None  ,A_     :      Any=None  ,A_     :      List[Any]=-1  ,A_     :      Union[str, Any]=False  ,)     ->   int:
							A						   =   self.num_layers
							try:
								A						   =   self.bert(
								    __lowerCAmelCase  ,attention_mask=__lowerCAmelCase  ,token_type_ids=__lowerCAmelCase  ,position_ids=__lowerCAmelCase  ,head_mask=__lowerCAmelCase  ,inputs_embeds=__lowerCAmelCase  ,)
								# sequence_output, pooled_output, (hidden_states), (attentions), highway exits

								A						   =   outputs[1]

								A						   =   self.dropout(__lowerCAmelCase      )
								A						   =   self.classifier(__lowerCAmelCase      )
								A						   =   (logits,) + outputs[2:]  # add hidden states and attention if they are here
							except HighwayException as e:
								A						   =   e.message
								A						   =   e.exit_layer
								A						   =   outputs[0]

							if not self.training:
								A						   =   entropy(__lowerCAmelCase      )
								A						   =   []
								A						   =   []
							if labels is not None:
								if self.num_labels == 1:
									#  We are doing regression
									A						   =   MSELoss()
									A						   =   loss_fct(logits.view(-1      )  ,labels.view(-1      )      )
								else:
									A						   =   CrossEntropyLoss()
									A						   =   loss_fct(logits.view(-1  ,self.num_labels      )  ,labels.view(-1      )      )

								# work with highway exits
								A						   =   []
								for highway_exit in outputs[-1]:
									A						   =   highway_exit[0]
									if not self.training:
										highway_logits_all.append(__lowerCAmelCase      )
										highway_entropy.append(highway_exit[2]      )
									if self.num_labels == 1:
										#  We are doing regression
										A						   =   MSELoss()
										A						   =   loss_fct(highway_logits.view(-1      )  ,labels.view(-1      )      )
									else:
										A						   =   CrossEntropyLoss()
										A						   =   loss_fct(highway_logits.view(-1  ,self.num_labels      )  ,labels.view(-1      )      )
									highway_losses.append(__lowerCAmelCase      )

								if train_highway:
									A						   =   (sum(highway_losses[:-1]      ),) + outputs
									# exclude the final highway, of course
								else:
									A						   =   (loss,) + outputs
							if not self.training:
								A						   =   outputs + ((original_entropy, highway_entropy), exit_layer)
								if output_layer >= 0:
									A						   =   (
									    (outputs[0],) + (highway_logits_all[output_layer],) + outputs[2:]
									)  # use the highway of the last layer

							return outputs  # (loss), logits, (hidden_states), (attentions), (highway_exits)


"""simple docstring"""


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







class 				lowerCAmelCase_				:



						'''simple docstring'''


						def __init__( self     :      Dict      )     ->   int:
							A						   =   {}


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      Union[str, Any]  ,A_     :      Any  ,A_     :      Optional[Any]=1      )     ->   int:
							if self.graph.get(A_      ):
								if self.graph[u].count([w, v]      ) == 0:
									self.graph[u].append([w, v]      )
							else:
								A						   =   [[w, v]]
							if not self.graph.get(A_      ):
								A						   =   []


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Optional[int]:
							return list(self.graph      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Union[str, Any]  ,A_     :      Dict      )     ->   Optional[Any]:
							if self.graph.get(A_      ):
								for _ in self.graph[u]:
									if _[1] == v:
										self.graph[u].remove(A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      int=-2  ,A_     :      Dict=-1      )     ->   str:
							if s == d:
								return []
							A						   =   []
							A						   =   []
							if s == -2:
								A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   s

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      Any=-1      )     ->   int:
							if c == -1:
								A						   =   floor(random() * 1_0000      ) + 10
							for i in range(A_      ):
								# every vertex has max 100 edges
								for _ in range(floor(random() * 102      ) + 1      ):
									A						   =   floor(random() * c      ) + 1
									if n != i:
										self.add_pair(A_  ,A_  ,1      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      Union[str, Any]=-2      )     ->   Optional[Any]:
							A						   =   deque()
							A						   =   []
							if s == -2:
								A						   =   list(self.graph      )[0]
							d.append(A_      )
							visited.append(A_      )
							while d:
								A						   =   d.popleft()
								if len(self.graph[s]      ) != 0:
									for node in self.graph[s]:
										if visited.count(node[1]      ) < 1:
											d.append(node[1]      )
											visited.append(node[1]      )
							return visited


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Tuple      )     ->   Any:
							A						   =   0
							for x in self.graph:
								for y in self.graph[x]:
									if y[1] == u:
										count += 1
							return count


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict  ,A_     :      Union[str, Any]      )     ->   str:
							return len(self.graph[u]      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      Union[str, Any]=-2      )     ->   Any:
							A						   =   []
							A						   =   []
							if s == -2:
								A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   s
							A						   =   []

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Tuple:
							A						   =   []
							A						   =   []
							A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   -2
							A						   =   []
							A						   =   s
							A						   =   False
							A						   =   set()

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   Optional[int]:
							A						   =   []
							A						   =   []
							A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   -2
							A						   =   []
							A						   =   s
							A						   =   False
							A						   =   set()

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict  ,A_     :      Tuple=-2  ,A_     :      List[str]=-1      )     ->   str:
							A						   =   time()
							self.dfs(A_  ,A_      )
							A						   =   time()
							return end - begin




						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]  ,A_     :      Union[str, Any]=-2      )     ->   Dict:
							A						   =   time()
							self.bfs(A_      )
							A						   =   time()
							return end - begin







class 				lowerCAmelCase_				:



						'''simple docstring'''


						def __init__( self     :      List[Any]      )     ->   Tuple:
							A						   =   {}


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any  ,A_     :      Optional[Any]  ,A_     :      str  ,A_     :      List[str]=1      )     ->   Dict:
							# check if the u exists
							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
								A						   =   [[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
								A						   =   [[w, u]]


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,A_     :      List[Any]  ,A_     :      List[str]      )     ->   List[Any]:
							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 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,A_     :      List[str]=-2  ,A_     :      List[Any]=-1      )     ->   int:
							if s == d:
								return []
							A						   =   []
							A						   =   []
							if s == -2:
								A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   s

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Optional[int]=-1      )     ->   List[Any]:
							if c == -1:
								A						   =   floor(random() * 1_0000      ) + 10
							for i in range(A_      ):
								# every vertex has max 100 edges
								for _ in range(floor(random() * 102      ) + 1      ):
									A						   =   floor(random() * c      ) + 1
									if n != i:
										self.add_pair(A_  ,A_  ,1      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      Dict=-2      )     ->   List[Any]:
							A						   =   deque()
							A						   =   []
							if s == -2:
								A						   =   list(self.graph      )[0]
							d.append(A_      )
							visited.append(A_      )
							while d:
								A						   =   d.popleft()
								if len(self.graph[s]      ) != 0:
									for node in self.graph[s]:
										if visited.count(node[1]      ) < 1:
											d.append(node[1]      )
											visited.append(node[1]      )
							return visited


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]  ,A_     :      Optional[Any]      )     ->   List[Any]:
							return len(self.graph[u]      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   List[Any]:
							A						   =   []
							A						   =   []
							A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   -2
							A						   =   []
							A						   =   s
							A						   =   False
							A						   =   set()

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   Any:
							A						   =   []
							A						   =   []
							A						   =   list(self.graph      )[0]
							stack.append(A_      )
							visited.append(A_      )
							A						   =   -2
							A						   =   []
							A						   =   s
							A						   =   False
							A						   =   set()

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

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

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Any:
							return list(self.graph      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      Optional[Any]=-2  ,A_     :      List[str]=-1      )     ->   Any:
							A						   =   time()
							self.dfs(A_  ,A_      )
							A						   =   time()
							return end - begin




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      List[Any]=-2      )     ->   Union[str, Any]:
							A						   =   time()
							self.bfs(A_      )
							A						   =   time()
							return end - begin