


'''simple docstring'''

from typing import TYPE_CHECKING

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


a_  :				int						= {
    """configuration_distilbert""": [
        """DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """DistilBertConfig""",
        """DistilBertOnnxConfig""",
    ],
    """tokenization_distilbert""": ["""DistilBertTokenizer"""],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     a_  :				Union[str, Any]						= ["""DistilBertTokenizerFast"""]

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     a_  :				List[str]						= [
         """DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """DistilBertForMaskedLM""",
         """DistilBertForMultipleChoice""",
         """DistilBertForQuestionAnswering""",
         """DistilBertForSequenceClassification""",
         """DistilBertForTokenClassification""",
         """DistilBertModel""",
         """DistilBertPreTrainedModel""",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     a_  :				Tuple						= [
         """TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
         """TFDistilBertForMaskedLM""",
         """TFDistilBertForMultipleChoice""",
         """TFDistilBertForQuestionAnswering""",
         """TFDistilBertForSequenceClassification""",
         """TFDistilBertForTokenClassification""",
         """TFDistilBertMainLayer""",
         """TFDistilBertModel""",
         """TFDistilBertPreTrainedModel""",
     ]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     a_  :				str						= [
         """FlaxDistilBertForMaskedLM""",
         """FlaxDistilBertForMultipleChoice""",
         """FlaxDistilBertForQuestionAnswering""",
         """FlaxDistilBertForSequenceClassification""",
         """FlaxDistilBertForTokenClassification""",
         """FlaxDistilBertModel""",
         """FlaxDistilBertPreTrainedModel""",
     ]


if TYPE_CHECKING:
     from .configuration_distilbert import (
         DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
         DistilBertConfig,
         DistilBertOnnxConfig,
     )
     from .tokenization_distilbert import DistilBertTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_distilbert_fast import DistilBertTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_distilbert import (
              DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              DistilBertForMaskedLM,
              DistilBertForMultipleChoice,
              DistilBertForQuestionAnswering,
              DistilBertForSequenceClassification,
              DistilBertForTokenClassification,
              DistilBertModel,
              DistilBertPreTrainedModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_distilbert import (
              TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFDistilBertForMaskedLM,
              TFDistilBertForMultipleChoice,
              TFDistilBertForQuestionAnswering,
              TFDistilBertForSequenceClassification,
              TFDistilBertForTokenClassification,
              TFDistilBertMainLayer,
              TFDistilBertModel,
              TFDistilBertPreTrainedModel,
          )

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_distilbert import (
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertModel,
              FlaxDistilBertPreTrainedModel,
          )

else:
     import sys

     a_  :				int						= _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)







'''simple docstring'''

from __future__ import annotations

from typing import Generic, TypeVar

a_  :				List[str]						= TypeVar("""T""")





class      snake_case    (    Generic[T]			):





  """simple docstring"""




  def __init__(    self			,  UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  data
   lowerCamelCase_      =  self
   lowerCamelCase_      =  0





class      snake_case    (    Generic[T]			):





  """simple docstring"""




  def __init__(    self     ):







   """simple docstring"""
   # map from node name to the node object
   lowerCamelCase_      =  {}






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   # create a new set with x as its member
   lowerCamelCase_      =  DisjointSetTreeNode(UpperCamelCase     )






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   # find the set x belongs to (with path-compression)
   lowerCamelCase_      =  self.map[data]
   if elem_ref != elem_ref.parent:
    lowerCamelCase_      =  self.find_set(elem_ref.parent.data     )
   return elem_ref.parent






  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase     ):







   """simple docstring"""
   # helper function for union operation
   if nodea.rank > nodea.rank:
    lowerCamelCase_      =  nodea
   else:
    lowerCamelCase_      =  nodea
    if nodea.rank == nodea.rank:
     nodea.rank += 1







  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase     ):







   """simple docstring"""
   # merge 2 disjoint sets
   self.link(self.find_set(UpperCamelCase     )			,  self.find_set(UpperCamelCase     )     )





class      snake_case    (    Generic[T]			):





  """simple docstring"""




  def __init__(    self     ):







   """simple docstring"""
   # connections: map from the node to the neighbouring nodes (with weights)
   lowerCamelCase_      =  {}






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   # add a node ONLY if its not present in the graph
   if node not in self.connections:
    lowerCamelCase_      =  {}






  def   snake_case		(    self			,  UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase     ):







   """simple docstring"""
   # add an edge with the given weight
   self.add_node(UpperCamelCase     )
   self.add_node(UpperCamelCase     )
   lowerCamelCase_      =  weight
   lowerCamelCase_      =  weight







  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  []
   lowerCamelCase_      =  set()
   for start in self.connections:
    for end in self.connections[start]:
     if (start, end) not in seen:
      seen.add((end, start)     )
      edges.append((start, end, self.connections[start][end])     )
   edges.sort(key=lambda UpperCamelCase     : x[2]     )

   # creating the disjoint set
   lowerCamelCase_      =  DisjointSetTree[T]()
   for node in self.connections:
    disjoint_set.make_set(UpperCamelCase     )

   # MST generation
   lowerCamelCase_      =  0
   lowerCamelCase_      =  0
   lowerCamelCase_      =  GraphUndirectedWeighted[T]()
   while num_edges < len(self.connections     ) - 1:
    lowerCamelCase_ ,lowerCamelCase_ ,lowerCamelCase_      =  edges[index]
    index += 1
    lowerCamelCase_      =  disjoint_set.find_set(UpperCamelCase     )
    lowerCamelCase_      =  disjoint_set.find_set(UpperCamelCase     )
    if parent_u != parent_v:
     num_edges += 1
     graph.add_edge(UpperCamelCase			,  UpperCamelCase			,  UpperCamelCase     )
     disjoint_set.union(UpperCamelCase			,  UpperCamelCase     )
   return graph



