


'''simple docstring'''







from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__:    int					    =       {'''configuration_focalnet''': ['''FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FocalNetConfig''']}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Optional[Any]					    =       [
       '''FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''FocalNetForImageClassification''',
       '''FocalNetForMaskedImageModeling''',
       '''FocalNetBackbone''',
       '''FocalNetModel''',
       '''FocalNetPreTrainedModel''',
   ]

if TYPE_CHECKING:
   from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_focalnet import (
          FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
          FocalNetBackbone,
          FocalNetForImageClassification,
          FocalNetForMaskedImageModeling,
          FocalNetModel,
          FocalNetPreTrainedModel,
      )

else:
   import sys

   A__:    Optional[Any]					    =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






'''simple docstring'''







class A__       :






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




             '''simple docstring'''
             _a    : Tuple     					=0
             _a    : Any     					=0
             _a    : int     					={}






      def __UpperCAmelCase       ( self			:Any     ,						SCREAMING_SNAKE_CASE			:List[str]	)       ->					Optional[int]:




             '''simple docstring'''
             if vertex not in self.adjacency:
                    _a    : Dict     					={}
                    self.num_vertices += 1






      def __UpperCAmelCase       ( self			:Optional[Any]     ,						SCREAMING_SNAKE_CASE			:str     ,						SCREAMING_SNAKE_CASE			:str     ,						SCREAMING_SNAKE_CASE			:Any	)       ->					List[str]:




             '''simple docstring'''
             self.add_vertex(SCREAMING_SNAKE_CASE	)
             self.add_vertex(SCREAMING_SNAKE_CASE	)

             if head == tail:
                    return

             _a    : Any     					=weight
             _a    : Tuple     					=weight






      def __UpperCAmelCase       ( self			:Dict	)       ->					Optional[int]:




             '''simple docstring'''
             _a    : Union[str, Any]     					=self.get_edges()
             for edge in edges:
                    _a					,    _a					,    _a    : List[str]     					=edge
                    edges.remove((tail, head, weight)	)
             for i in range(len(SCREAMING_SNAKE_CASE	)	):
                    _a    : str     					=list(edges[i]	)

             edges.sort(key=lambda SCREAMING_SNAKE_CASE	: e[2]	)
             for i in range(len(SCREAMING_SNAKE_CASE	) - 1	):
                    if edges[i][2] >= edges[i + 1][2]:
                           _a    : Union[str, Any]     					=edges[i][2] + 1
             for edge in edges:
                    _a					,    _a					,    _a    : Tuple     					=edge
                    _a    : Tuple     					=weight
                    _a    : List[Any]     					=weight






      def __str__( self			:int	)       ->					str:




             '''simple docstring'''
             _a    : int     					=""""""
             for tail in self.adjacency:
                    for head in self.adjacency[tail]:
                           _a    : str     					=self.adjacency[head][tail]
                           string += f"{head} -> {tail} == {weight}\n"
             return string.rstrip("""\n"""	)






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




             '''simple docstring'''
             _a    : Union[str, Any]     					=[]
             for tail in self.adjacency:
                    for head in self.adjacency[tail]:
                           output.append((tail, head, self.adjacency[head][tail])	)
             return output






      def __UpperCAmelCase       ( self			:List[Any]	)       ->					List[Any]:




             '''simple docstring'''
             return self.adjacency.keys()






      @staticmethod
      def __UpperCAmelCase       ( SCREAMING_SNAKE_CASE			:Dict=None     ,						SCREAMING_SNAKE_CASE			:List[Any]=None	)       ->					Optional[int]:




             '''simple docstring'''
             _a    : str     					=Graph()
             if vertices is None:
                    _a    : Union[str, Any]     					=[]
             if edges is None:
                    _a    : List[Any]     					=[]
             for vertex in vertices:
                    g.add_vertex(SCREAMING_SNAKE_CASE	)
             for edge in edges:
                    g.add_edge(*SCREAMING_SNAKE_CASE	)
             return g







      class A__       :






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




                   '''simple docstring'''
                   _a    : Optional[int]     					={}
                   _a    : List[str]     					={}






            def __len__( self			:List[Any]	)       ->					List[Any]:




                   '''simple docstring'''
                   return len(self.parent	)






            def __UpperCAmelCase       ( self			:Tuple     ,						SCREAMING_SNAKE_CASE			:Tuple	)       ->					Dict:




                   '''simple docstring'''
                   if item in self.parent:
                          return self.find(SCREAMING_SNAKE_CASE	)

                   _a    : Optional[Any]     					=item
                   _a    : List[str]     					=0
                   return item






            def __UpperCAmelCase       ( self			:int     ,						SCREAMING_SNAKE_CASE			:Dict	)       ->					List[str]:




                   '''simple docstring'''
                   if item not in self.parent:
                          return self.make_set(SCREAMING_SNAKE_CASE	)
                   if item != self.parent[item]:
                          _a    : str     					=self.find(self.parent[item]	)
                   return self.parent[item]






            def __UpperCAmelCase       ( self			:Optional[int]     ,						SCREAMING_SNAKE_CASE			:Tuple     ,						SCREAMING_SNAKE_CASE			:List[Any]	)       ->					Optional[Any]:




                   '''simple docstring'''
                   _a    : Optional[int]     					=self.find(SCREAMING_SNAKE_CASE	)
                   _a    : Dict     					=self.find(SCREAMING_SNAKE_CASE	)

                   if roota == roota:
                          return roota

                   if self.rank[roota] > self.rank[roota]:
                          _a    : Any     					=roota
                          return roota

                   if self.rank[roota] < self.rank[roota]:
                          _a    : List[str]     					=roota
                          return roota

                   if self.rank[roota] == self.rank[roota]:
                          self.rank[roota] += 1
                          _a    : List[Any]     					=roota
                          return roota
                   return None






      @staticmethod
      def __UpperCAmelCase       ( SCREAMING_SNAKE_CASE			:Dict	)       ->					Union[str, Any]:




             '''simple docstring'''
             _a    : Any     					=graph.num_vertices

             _a    : Union[str, Any]     					=Graph.UnionFind()
             _a    : Optional[int]     					=[]
             while num_components > 1:
                    _a    : str     					={}
                    for vertex in graph.get_vertices():
                           _a    : List[str]     					=-1

                    _a    : Any     					=graph.get_edges()
                    for edge in edges:
                           _a					,    _a					,    _a    : Tuple     					=edge
                           edges.remove((tail, head, weight)	)
                    for edge in edges:
                           _a					,    _a					,    _a    : Any     					=edge
                           _a    : Any     					=union_find.find(SCREAMING_SNAKE_CASE	)
                           _a    : List[Any]     					=union_find.find(SCREAMING_SNAKE_CASE	)
                           if seta != seta:
                                  if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                         _a    : Optional[int]     					=[head, tail, weight]

                                  if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                                         _a    : List[Any]     					=[head, tail, weight]
                    for vertex in cheap_edge:
                           if cheap_edge[vertex] != -1:
                                  _a					,    _a					,    _a    : Optional[Any]     					=cheap_edge[vertex]
                                  if union_find.find(SCREAMING_SNAKE_CASE	) != union_find.find(SCREAMING_SNAKE_CASE	):
                                         union_find.union(SCREAMING_SNAKE_CASE     ,						SCREAMING_SNAKE_CASE	)
                                         mst_edges.append(cheap_edge[vertex]	)
                                         _a    : str     					=num_components - 1
             _a    : str     					=Graph.build(edges=SCREAMING_SNAKE_CASE	)
             return mst


