


from __future__ import annotations

import os
from collections.abc import Mapping

_A			=						tuple[int, int]






class    UpperCAmelCase__	:



				"""simple docstring"""






				def __init__(      self ,       A_ ,       A_   )  ->	List[Any]:
									__UpperCamelCase   							=vertices
									__UpperCamelCase   							={
									    (min(_UpperCamelCase   ), max(_UpperCamelCase   )): weight for edge, weight in edges.items()
									}






				def _a (      self ,       A_ ,       A_   )  ->	List[str]:
									self.vertices.add(edge[0]   )
									self.vertices.add(edge[1]   )
									__UpperCamelCase   							=weight






				def _a (      self   )  ->	List[str]:
									__UpperCamelCase   							=Graph({min(self.vertices   )} ,       {}   )
									__UpperCamelCase   							=42
									__UpperCamelCase   							=42
									__UpperCamelCase   							=42
									__UpperCamelCase   							=42

									while len(subgraph.vertices   ) < len(self.vertices   ):
														__UpperCamelCase   							=max(self.edges.values()   ) + 1
														for edge, weight in self.edges.items():
																			if (edge[0] in subgraph.vertices) ^ (edge[1] in subgraph.vertices):
																								if weight < min_weight:
																													__UpperCamelCase   							=edge
																													__UpperCamelCase   							=weight

														subgraph.add_edge(_UpperCamelCase ,       _UpperCamelCase   )

									return subgraph

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : str = "p107_network.txt"    ):
					__UpperCamelCase   							=os.path.abspath(os.path.dirname(lowerCamelCase_    )    )
					__UpperCamelCase   							=os.path.join(lowerCamelCase_      ,					lowerCamelCase_    )
					__UpperCamelCase   							={}
					__UpperCamelCase   							=42
					__UpperCamelCase   							=42
					__UpperCamelCase   							=42

					with open(lowerCamelCase_    ) as f:
										__UpperCamelCase   							=f.read().strip().split('\n'    )

					__UpperCamelCase   							=[line.split(','    ) for line in data]

					for edgea in range(1      ,					len(lowerCamelCase_    )    ):
										for edgea in range(lowerCamelCase_    ):
															if adjaceny_matrix[edgea][edgea] != "-":
																				__UpperCamelCase   							=int(adjaceny_matrix[edgea][edgea]    )

					__UpperCamelCase   							=Graph(set(range(len(lowerCamelCase_    )    )    )      ,					lowerCamelCase_    )

					__UpperCamelCase   							=graph.prims_algorithm()

					__UpperCamelCase   							=sum(graph.edges.values()    )
					__UpperCamelCase   							=sum(subgraph.edges.values()    )

					return initial_total - optimal_total


if __name__ == "__main__":
			print(f"""{solution() = }""")









from __future__ import annotations

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int    ):
     if b == 0:
          return (1, 0)
     ((__UpperCamelCase)							,				(__UpperCamelCase))   							=extended_euclid(SCREAMING_SNAKE_CASE__      ,					a % b    )
     __UpperCamelCase   							=a // b
     return (y, x - k * y)

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int    ):
     ((__UpperCamelCase)							,				(__UpperCamelCase))   							=extended_euclid(SCREAMING_SNAKE_CASE__      ,					SCREAMING_SNAKE_CASE__    )
     __UpperCamelCase   							=na * na
     __UpperCamelCase   							=ra * x * na + ra * y * na
     return (n % m + m) % m

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int    ):
     ((__UpperCamelCase)							,				(__UpperCamelCase))   							=extended_euclid(SCREAMING_SNAKE_CASE__      ,					SCREAMING_SNAKE_CASE__    )
     if b < 0:
          __UpperCamelCase   							=(b % n + n) % n
     return b

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int      ,					SCREAMING_SNAKE_CASE__      : int    ):
     __UpperCamelCase							,				__UpperCamelCase   							=invert_modulo(SCREAMING_SNAKE_CASE__      ,					SCREAMING_SNAKE_CASE__    ), invert_modulo(SCREAMING_SNAKE_CASE__      ,					SCREAMING_SNAKE_CASE__    )
     __UpperCamelCase   							=na * na
     __UpperCamelCase   							=ra * x * na + ra * y * na
     return (n % m + m) % m


if __name__ == "__main__":
   from doctest import testmod

   testmod(name='chinese_remainder_theorem', verbose=True)
   testmod(name='chinese_remainder_theorem2', verbose=True)
   testmod(name='invert_modulo', verbose=True)
   testmod(name='extended_euclid', verbose=True)





