

import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


_lowerCAmelCase  :      Dict			 ={
    """<""": operator.lt,
    """<=""": operator.le,
    """==""": operator.eq,
    """!=""": operator.ne,
    """>=""": operator.ge,
    """>""": operator.gt,
}



def 			_A	(      SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      ):
	if got_ver is None or want_ver is None:
		raise ValueError(
		    f"Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider"
		    f" reinstalling {pkg}."      )
	if not ops[op](version.parse(SCREAMING_SNAKE_CASE      )	,version.parse(SCREAMING_SNAKE_CASE      )      ):
		raise ImportError(
		    f"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"      )



def 			_A	(      SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE = None      ):
	UpperCAmelCase__:	Tuple									= f"\n{hint}" if hint is not None else ""

	# non-versioned check
	if re.match(R"^[\w_\-\d]+$"	,SCREAMING_SNAKE_CASE      ):
		UpperCAmelCase__							,						UpperCAmelCase__							,						UpperCAmelCase__:	Optional[Any]									= requirement, None, None
	else:
		UpperCAmelCase__:	Dict									= re.findall(R"^([^!=<>\s]+)([\s!=<>]{1,2}.+)"	,SCREAMING_SNAKE_CASE      )
		if not match:
			raise ValueError(
			    "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but"
			    f" got {requirement}"      )
		UpperCAmelCase__							,						UpperCAmelCase__:	str									= match[0]
		UpperCAmelCase__:	str									= want_full.split(","      )  # there could be multiple requirements
		UpperCAmelCase__:	Optional[int]									= {}
		for w in want_range:
			UpperCAmelCase__:	Dict									= re.findall(R"^([\s!=<>]{1,2})(.+)"	,SCREAMING_SNAKE_CASE      )
			if not match:
				raise ValueError(
				    "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,"
				    f" but got {requirement}"      )
			UpperCAmelCase__							,						UpperCAmelCase__:	List[str]									= match[0]
			UpperCAmelCase__:	Any									= want_ver
			if op not in ops:
				raise ValueError(f"{requirement}: need one of {list(ops.keys()      )}, but got {op}"      )

    # special case
	if pkg == "python":
		UpperCAmelCase__:	str									= ".".join([str(SCREAMING_SNAKE_CASE      ) for x in sys.version_info[:3]]      )
		for op, want_ver in wanted.items():
			_compare_versions(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      )
		return

	# check if any version is installed
	try:
		UpperCAmelCase__:	List[str]									= importlib.metadata.version(SCREAMING_SNAKE_CASE      )
	except importlib.metadata.PackageNotFoundError:
		raise importlib.metadata.PackageNotFoundError(
		    f"The '{requirement}' distribution was not found and is required by this application. {hint}"      )

	# check that the right version is installed if version number or a range was provided
	if want_ver is not None:
		for op, want_ver in wanted.items():
			_compare_versions(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      )



def 			_A	(      SCREAMING_SNAKE_CASE      ):
	UpperCAmelCase__:	Optional[Any]									= "Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main"
	return require_version(SCREAMING_SNAKE_CASE	,SCREAMING_SNAKE_CASE      )


from __future__ import annotations

from typing import Any

class __UpperCamelCase     :






					'''simple docstring'''



					def __init__(				self				,      lowerCamelCase__						):
						UpperCAmelCase__:	Optional[int]									= num_of_nodes
						UpperCAmelCase__:	list[list[int]]									= []
						UpperCAmelCase__:	dict[int, int]									= {}





					def    _UpperCAmelCase    (				self				,      lowerCamelCase__				,      lowerCamelCase__				,      lowerCamelCase__						):
						self.m_edges.append([u_node, v_node, weight]						)





					def    _UpperCAmelCase    (				self				,      lowerCamelCase__						):

						if self.m_component[u_node] == u_node:
							return u_node
						return self.find_component(self.m_component[u_node]						)





					def    _UpperCAmelCase    (				self				,      lowerCamelCase__						):

						if self.m_component[u_node] != u_node:
							for k in self.m_component:
								UpperCAmelCase__:	Optional[Any]									= self.find_component(lowerCamelCase__						)





					def    _UpperCAmelCase    (				self				,      lowerCamelCase__				,      lowerCamelCase__				,      lowerCamelCase__						):

						if component_size[u_node] <= component_size[v_node]:
							UpperCAmelCase__:	Tuple									= v_node
							component_size[v_node] += component_size[u_node]
							self.set_component(lowerCamelCase__						)

						elif component_size[u_node] >= component_size[v_node]:
							UpperCAmelCase__:	Dict									= self.find_component(lowerCamelCase__						)
							component_size[u_node] += component_size[v_node]
							self.set_component(lowerCamelCase__						)





					def    _UpperCAmelCase    (				self						):
						UpperCAmelCase__:	Dict									= []
						UpperCAmelCase__:	int									= 0

						UpperCAmelCase__:	list[Any]									= [-1] * self.m_num_of_nodes

						# A list of components (initialized to all of the nodes)
						for node in range(self.m_num_of_nodes						):
							self.m_component.update({node: node}						)
							component_size.append(1						)

						UpperCAmelCase__:	Union[str, Any]									= self.m_num_of_nodes

						while num_of_components > 1:
							for edge in self.m_edges:
								UpperCAmelCase__							,						UpperCAmelCase__							,						UpperCAmelCase__:	str									= edge

								UpperCAmelCase__:	str									= self.m_component[u]
								UpperCAmelCase__:	Optional[Any]									= self.m_component[v]

								if u_component != v_component:

									for component in (u_component, v_component):
										if (
										    minimum_weight_edge[component] == -1
										    or minimum_weight_edge[component][2] > w
										):
											UpperCAmelCase__:	List[Any]									= [u, v, w]

							for edge in minimum_weight_edge:
								if isinstance(lowerCamelCase__				,      lowerCamelCase__						):
									UpperCAmelCase__							,						UpperCAmelCase__							,						UpperCAmelCase__:	str									= edge

									UpperCAmelCase__:	str									= self.m_component[u]
									UpperCAmelCase__:	int									= self.m_component[v]

									if u_component != v_component:
										mst_weight += w
										self.union(lowerCamelCase__				,      lowerCamelCase__				,      lowerCamelCase__						)
										print(F"Added edge [{u} - {v}]\nAdded weight: {w}\n"						)
										num_of_components -= 1

							UpperCAmelCase__:	Any									= [-1] * self.m_num_of_nodes
						print(F"The total weight of the minimal spanning tree is: {mst_weight}"						)



def 			_A	(      ):
	pass


if __name__ == "__main__":
					import doctest

					doctest.testmod()