
"""simple docstring"""




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







class   _lowercase						:


     '''simple docstring'''





     def __init__(      self  )->					int:
          UpperCAmelCase__							: Any 							=						{}



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase=1  )->					List[str]:
          if self.graph.get(__UpperCamelCase  ):
               if self.graph[u].count([w, v]  ) == 0:
                    self.graph[u].append([w, v]  )
          else:
               UpperCAmelCase__							: Optional[Any] 							=						[[w, v]]
          if not self.graph.get(__UpperCamelCase  ):
               UpperCAmelCase__							: Any 							=						[]



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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase  )->					List[Any]:
          if self.graph.get(__UpperCamelCase  ):
               for _ in self.graph[u]:
                    if _[1] == v:
                         self.graph[u].remove(__UpperCamelCase  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2 ,			__UpperCamelCase=-1  )->					Dict:
          if s == d:
               return []
          UpperCAmelCase__							: Dict 							=						[]
          UpperCAmelCase__							: Tuple 							=						[]
          if s == -2:
               UpperCAmelCase__							: Union[str, Any] 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: Any 							=						s

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

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

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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-1  )->					str:
          if c == -1:
               UpperCAmelCase__							: Tuple 							=						floor(random() * 1_00_00  ) + 10
          for i in range(__UpperCamelCase  ):
               # 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(__UpperCamelCase ,			__UpperCamelCase ,			1  )



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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					Union[str, Any]:
          return len(self.graph[u]  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2  )->					Dict:
          UpperCAmelCase__							: Any 							=						[]
          UpperCAmelCase__							: str 							=						[]
          if s == -2:
               UpperCAmelCase__							: int 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: int 							=						s
          UpperCAmelCase__							: Union[str, Any] 							=						[]

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

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

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



     def  lowerCAmelCase__       (      self  )->					int:
          UpperCAmelCase__							: str 							=						[]
          UpperCAmelCase__							: Optional[int] 							=						[]
          UpperCAmelCase__							: Union[str, Any] 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: Any 							=						-2
          UpperCAmelCase__							: Union[str, Any] 							=						[]
          UpperCAmelCase__							: Any 							=						s
          UpperCAmelCase__							: str 							=						False
          UpperCAmelCase__							: Tuple 							=						set()

          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]  ) > 0
                             and node[1] != parent
                             and indirect_parents.count(node[1]  ) > 0
                             and not on_the_way_back
                         ):
                              UpperCAmelCase__							: 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]  )
                              UpperCAmelCase__							: Any 							=						node[1]
                              break

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

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



     def  lowerCAmelCase__       (      self  )->					Any:
          UpperCAmelCase__							: str 							=						[]
          UpperCAmelCase__							: List[Any] 							=						[]
          UpperCAmelCase__							: Optional[int] 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: Optional[Any] 							=						-2
          UpperCAmelCase__							: Optional[int] 							=						[]
          UpperCAmelCase__							: str 							=						s
          UpperCAmelCase__							: Any 							=						False
          UpperCAmelCase__							: Optional[Any] 							=						set()

          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]  ) > 0
                             and node[1] != parent
                             and indirect_parents.count(node[1]  ) > 0
                             and not on_the_way_back
                         ):
                              UpperCAmelCase__							: Optional[int] 							=						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]  )
                              UpperCAmelCase__							: int 							=						node[1]
                              break

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

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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2 ,			__UpperCamelCase=-1  )->					List[str]:
          UpperCAmelCase__							: Dict 							=						time()
          self.dfs(__UpperCamelCase ,			__UpperCamelCase  )
          UpperCAmelCase__							: Optional[int] 							=						time()
          return end - begin



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2  )->					Optional[int]:
          UpperCAmelCase__							: Optional[Any] 							=						time()
          self.bfs(__UpperCamelCase  )
          UpperCAmelCase__							: Tuple 							=						time()
          return end - begin







class   _lowercase						:


     '''simple docstring'''





     def __init__(      self  )->					Union[str, Any]:
          UpperCAmelCase__							: List[Any] 							=						{}



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase ,			__UpperCamelCase=1  )->					Union[str, Any]:
          # 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
               UpperCAmelCase__							: int 							=						[[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
               UpperCAmelCase__							: Optional[int] 							=						[[w, u]]



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase ,			__UpperCamelCase  )->					int:
          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  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2 ,			__UpperCamelCase=-1  )->					Optional[int]:
          if s == d:
               return []
          UpperCAmelCase__							: Dict 							=						[]
          UpperCAmelCase__							: int 							=						[]
          if s == -2:
               UpperCAmelCase__							: Union[str, Any] 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: str 							=						s

          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]  ) < 1:
                              if node[1] == d:
                                   visited.append(__UpperCamelCase  )
                                   return visited
                              else:
                                   stack.append(node[1]  )
                                   visited.append(node[1]  )
                                   UpperCAmelCase__							: List[Any] 							=						node[1]
                                   break

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

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



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-1  )->					Optional[Any]:
          if c == -1:
               UpperCAmelCase__							: Dict 							=						floor(random() * 1_00_00  ) + 10
          for i in range(__UpperCamelCase  ):
               # every vertex has max 100 edges
               for _ in range(floor(random() * 1_02  ) + 1  ):
                    UpperCAmelCase__							: int 							=						floor(random() * c  ) + 1
                    if n != i:
                         self.add_pair(__UpperCamelCase ,			__UpperCamelCase ,			1  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2  )->					Any:
          UpperCAmelCase__							: int 							=						deque()
          UpperCAmelCase__							: str 							=						[]
          if s == -2:
               UpperCAmelCase__							: List[Any] 							=						list(self.graph  )[0]
          d.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          while d:
               UpperCAmelCase__							: Optional[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 ,			__UpperCamelCase  )->					str:
          return len(self.graph[u]  )



     def  lowerCAmelCase__       (      self  )->					Any:
          UpperCAmelCase__							: List[str] 							=						[]
          UpperCAmelCase__							: Optional[int] 							=						[]
          UpperCAmelCase__							: str 							=						list(self.graph  )[0]
          stack.append(__UpperCamelCase  )
          visited.append(__UpperCamelCase  )
          UpperCAmelCase__							: Any 							=						-2
          UpperCAmelCase__							: Optional[Any] 							=						[]
          UpperCAmelCase__							: int 							=						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__							: 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__							: 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]  )
                              UpperCAmelCase__							: Any 							=						node[1]
                              break

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

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



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

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

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



     def  lowerCAmelCase__       (      self  )->					str:
          return list(self.graph  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2 ,			__UpperCamelCase=-1  )->					int:
          UpperCAmelCase__							: str 							=						time()
          self.dfs(__UpperCamelCase ,			__UpperCamelCase  )
          UpperCAmelCase__							: List[Any] 							=						time()
          return end - begin



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=-2  )->					Tuple:
          UpperCAmelCase__							: int 							=						time()
          self.bfs(__UpperCamelCase  )
          UpperCAmelCase__							: str 							=						time()
          return end - begin





"""simple docstring"""




def 							a__ (				lowerCAmelCase	:       list       ,    lowerCAmelCase	:       list		):






     '''simple docstring'''
     _validate_point(lowerCAmelCase		)
     _validate_point(lowerCAmelCase		)
     if len(lowerCAmelCase		) != len(lowerCAmelCase		):
          raise ValueError("Both points must be in the same n-dimensional space"		)

     return float(sum(abs(a - b		) for a, b in zip(lowerCAmelCase       ,    lowerCAmelCase		)		)		)



def 							a__ (				lowerCAmelCase	:       list[float]		):






     '''simple docstring'''
     if point:
          if isinstance(lowerCAmelCase       ,    lowerCAmelCase		):
               for item in point:
                    if not isinstance(lowerCAmelCase       ,    (int, float)		):
                         UpperCAmelCase__							: Tuple 							=						(
                             "Expected a list of numbers as input, found "
                             F"{type(lowerCAmelCase		).__name__}"
                         )
                         raise TypeError(lowerCAmelCase		)
          else:
               UpperCAmelCase__							: Dict 							=						F"Expected a list of numbers as input, found {type(lowerCAmelCase		).__name__}"
               raise TypeError(lowerCAmelCase		)
     else:
          raise ValueError("Missing an input"		)



def 							a__ (				lowerCAmelCase	:       list       ,    lowerCAmelCase	:       list		):






     '''simple docstring'''
     _validate_point(lowerCAmelCase		)
     _validate_point(lowerCAmelCase		)
     if len(lowerCAmelCase		) != len(lowerCAmelCase		):
          raise ValueError("Both points must be in the same n-dimensional space"		)

     return float(sum(abs(x - y		) for x, y in zip(lowerCAmelCase       ,    lowerCAmelCase		)		)		)


if __name__ == "__main__":
    import doctest

    doctest.testmod()



