

class A__    :



 """simple docstring"""







 def __init__(		self :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					Tuple        =    0
      _lowerCAmelCase   :					str        =    0
      _lowerCAmelCase   :					str        =    {}

 def    __magic_name__       (		self :	str     ,						A_ :	List[str]       ):






      '''simple docstring'''




      if vertex not in self.adjacency:
           _lowerCAmelCase   :					Optional[Any]        =    {}
           self.num_vertices += 1

 def    __magic_name__       (		self :	List[str]     ,						A_ :	Dict     ,						A_ :	Tuple     ,						A_ :	Tuple       ):






      '''simple docstring'''




      self.add_vertex(A_       )
      self.add_vertex(A_       )

      if head == tail:
           return

      _lowerCAmelCase   :					List[str]        =    weight
      _lowerCAmelCase   :					List[Any]        =    weight

 def    __magic_name__       (		self :	Optional[int]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					List[Any]        =    self.get_edges()
      for edge in edges:
           _lowerCAmelCase   :					List[str]        =    edge
           edges.remove((tail, head, weight)       )
      for i in range(len(A_       )       ):
           _lowerCAmelCase   :					str        =    list(edges[i]       )

      edges.sort(key=lambda A_       : e[2]       )
      for i in range(len(A_       ) - 1       ):
           if edges[i][2] >= edges[i + 1][2]:
                _lowerCAmelCase   :					Tuple        =    edges[i][2] + 1
      for edge in edges:
           _lowerCAmelCase   :					Optional[int]        =    edge
           _lowerCAmelCase   :					int        =    weight
           _lowerCAmelCase   :					int        =    weight

 def __str__(		self :	Union[str, Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					List[str]        =    ""
      for tail in self.adjacency:
           for head in self.adjacency[tail]:
                _lowerCAmelCase   :					Any        =    self.adjacency[head][tail]
                string += F'''{head} -> {tail} == {weight}\n'''
      return string.rstrip("\n"       )

 def    __magic_name__       (		self :	Optional[Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					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    __magic_name__       (		self :	str       ):






      '''simple docstring'''




      return self.adjacency.keys()

 @staticmethod
 def    __magic_name__       (		A_ :	int=None     ,						A_ :	Optional[Any]=None       ):






      '''simple docstring'''




      _lowerCAmelCase   :					List[str]        =    Graph()
      if vertices is None:
           _lowerCAmelCase   :					Optional[Any]        =    []
      if edges is None:
           _lowerCAmelCase   :					Union[str, Any]        =    []
      for vertex in vertices:
           g.add_vertex(A_       )
      for edge in edges:
           g.add_edge(*A_       )
      return g





 class A__    :



  """simple docstring"""







  def __init__(		self :	Union[str, Any]       ):






       '''simple docstring'''




       _lowerCAmelCase   :					Optional[int]        =    {}
       _lowerCAmelCase   :					Optional[int]        =    {}

  def __len__(		self :	Tuple       ):






       '''simple docstring'''




       return len(self.parent       )

  def    __magic_name__       (		self :	List[str]     ,						A_ :	int       ):






       '''simple docstring'''




       if item in self.parent:
            return self.find(A_       )

       _lowerCAmelCase   :					Any        =    item
       _lowerCAmelCase   :					Tuple        =    0
       return item

  def    __magic_name__       (		self :	Any     ,						A_ :	int       ):






       '''simple docstring'''




       if item not in self.parent:
            return self.make_set(A_       )
       if item != self.parent[item]:
            _lowerCAmelCase   :					List[Any]        =    self.find(self.parent[item]       )
       return self.parent[item]


  def    __magic_name__       (		self :	Tuple     ,						A_ :	List[str]     ,						A_ :	int       ):






       '''simple docstring'''




       _lowerCAmelCase   :					Optional[int]        =    self.find(A_       )
       _lowerCAmelCase   :					List[Any]        =    self.find(A_       )

       if roota == roota:
            return roota

       if self.rank[roota] > self.rank[roota]:
            _lowerCAmelCase   :					int        =    roota
            return roota

       if self.rank[roota] < self.rank[roota]:
            _lowerCAmelCase   :					Union[str, Any]        =    roota
            return roota

       if self.rank[roota] == self.rank[roota]:
            self.rank[roota] += 1
            _lowerCAmelCase   :					List[str]        =    roota
            return roota
       return None

 @staticmethod
 def    __magic_name__       (		A_ :	Union[str, Any]       ):






      '''simple docstring'''




      _lowerCAmelCase   :					int        =    graph.num_vertices

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

           _lowerCAmelCase   :					List[str]        =    graph.get_edges()
           for edge in edges:
                _lowerCAmelCase   :					Union[str, Any]        =    edge
                edges.remove((tail, head, weight)       )
           for edge in edges:
                _lowerCAmelCase   :					Dict        =    edge
                _lowerCAmelCase   :					List[str]        =    union_find.find(A_       )
                _lowerCAmelCase   :					Tuple        =    union_find.find(A_       )
                if seta != seta:
                     if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
                          _lowerCAmelCase   :					List[str]        =    [head, tail, weight]

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









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tensorflow_text_available, is_torch_available


__UpperCAmelCase    				=     {
    'configuration_ernie': ['ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ErnieConfig', 'ErnieOnnxConfig'],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase    				=     [
      'ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST',
      'ErnieForCausalLM',
      'ErnieForMaskedLM',
      'ErnieForMultipleChoice',
      'ErnieForNextSentencePrediction',
      'ErnieForPreTraining',
      'ErnieForQuestionAnswering',
      'ErnieForSequenceClassification',
      'ErnieForTokenClassification',
      'ErnieModel',
      'ErniePreTrainedModel',
  ]

if TYPE_CHECKING:
  from .configuration_ernie import ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieConfig, ErnieOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_ernie import (
        ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST,
        ErnieForCausalLM,
        ErnieForMaskedLM,
        ErnieForMultipleChoice,
        ErnieForNextSentencePrediction,
        ErnieForPreTraining,
        ErnieForQuestionAnswering,
        ErnieForSequenceClassification,
        ErnieForTokenClassification,
        ErnieModel,
        ErniePreTrainedModel,
    )

else:
  import sys

  __UpperCAmelCase    				=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






