


from __future__ import annotations

import os
from collections.abc import Mapping

lowerCAmelCase__			:      int								=tuple[int, int]







class 	__lowercase    :





							"""simple docstring"""







							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     set[int]					=					vertices
										SCREAMING_SNAKE_CASE_		:     dict[EdgeT, int]					=					{
										    (min(lowerCAmelCase__       ), max(lowerCAmelCase__       )): weight for edge, weight in edges.items()
										}






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										self.vertices.add(edge[0]       )
										self.vertices.add(edge[1]       )
										SCREAMING_SNAKE_CASE_		:     Tuple					=					weight






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Graph					=					Graph({min(self.vertices       )}			,						{}       )
										SCREAMING_SNAKE_CASE_		:     EdgeT
										SCREAMING_SNAKE_CASE_		:     int
										SCREAMING_SNAKE_CASE_		:     EdgeT
										SCREAMING_SNAKE_CASE_		:     int

										while len(subgraph.vertices       ) < len(self.vertices       ):
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					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:
																						SCREAMING_SNAKE_CASE_		:     Tuple					=					edge
																						SCREAMING_SNAKE_CASE_		:     Tuple					=					weight

													subgraph.add_edge(lowerCAmelCase__			,						lowerCAmelCase__       )

										return subgraph







def 						a__			(				A__ = "p107_network.txt"				):
			SCREAMING_SNAKE_CASE_		:     str					=					os.path.abspath(os.path.dirname(A__				)				)
			SCREAMING_SNAKE_CASE_		:     str					=					os.path.join(A__,      A__				)
			SCREAMING_SNAKE_CASE_		:     dict[EdgeT, int]					=					{}
			SCREAMING_SNAKE_CASE_		:     list[str]
			SCREAMING_SNAKE_CASE_		:     int
			SCREAMING_SNAKE_CASE_		:     int

			with open(A__				) as f:
						SCREAMING_SNAKE_CASE_		:     Dict					=					f.read().strip().split('\n'				)

			SCREAMING_SNAKE_CASE_		:     List[Any]					=					[line.split(','				) for line in data]

			for edgea in range(1,      len(A__				)				):
						for edgea in range(A__				):
									if adjaceny_matrix[edgea][edgea] != "-":
												SCREAMING_SNAKE_CASE_		:     Tuple					=					int(adjaceny_matrix[edgea][edgea]				)

			SCREAMING_SNAKE_CASE_		:     Graph					=					Graph(set(range(len(A__				)				)				),      A__				)

			SCREAMING_SNAKE_CASE_		:     Graph					=					graph.prims_algorithm()

			SCREAMING_SNAKE_CASE_		:     int					=					sum(graph.edges.values()				)
			SCREAMING_SNAKE_CASE_		:     int					=					sum(subgraph.edges.values()				)

			return initial_total - optimal_total


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













'''simple docstring'''



import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate


def 				lowercase_					(     __A			:							str      )							->   Union[str, Any]:



 """simple docstring"""




 return x + 2





class UpperCAmelCase_       (     unittest.TestCase					):




      """simple docstring"""




      def 					A__   (			self      :		Dict		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : Optional[int]						='''x = 3'''
       lowercase       : Any						={}
       lowercase       : Union[str, Any]						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       assert result == 3
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3}		)

       lowercase       : str						='''x = y'''
       lowercase       : Optional[int]						={'''y''': 5}
       lowercase       : List[str]						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       # evaluate returns the value of the last assignment.
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 5, '''y''': 5}		)






      def 					A__   (			self      :		str		)	->	Optional[int]:


       '''simple docstring'''

       lowercase       : Optional[int]						='''y = add_two(x)'''
       lowercase       : str						={'''x''': 3}
       lowercase       : List[str]						=evaluate(UpperCAmelCase  ,   {'''add_two''': add_two}  ,   state=UpperCAmelCase		)
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''y''': 5}		)

       # Won't work without the tool
       with CaptureStdout() as out:
        lowercase       : Optional[Any]						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       assert result is None
       assert "tried to execute add_two" in out.out






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


       '''simple docstring'''

       lowercase       : int						='''x = 3'''
       lowercase       : Dict						={}
       lowercase       : List[Any]						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       assert result == 3
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3}		)






      def 					A__   (			self      :		str		)	->	Tuple:


       '''simple docstring'''

       lowercase       : Optional[Any]						='''test_dict = {\'x\': x, \'y\': add_two(x)}'''
       lowercase       : str						={'''x''': 3}
       lowercase       : Tuple						=evaluate(UpperCAmelCase  ,   {'''add_two''': add_two}  ,   state=UpperCAmelCase		)
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''y''': 5}		)
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}		)






      def 					A__   (			self      :		Union[str, Any]		)	->	Union[str, Any]:


       '''simple docstring'''

       lowercase       : Optional[Any]						='''x = 3\ny = 5'''
       lowercase       : int						={}
       lowercase       : List[str]						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       # evaluate returns the value of the last assignment.
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''y''': 5}		)






      def 					A__   (			self      :		Any		)	->	Tuple:


       '''simple docstring'''

       lowercase       : List[str]						='''text = f\'This is x: {x}.\''''
       lowercase       : Union[str, Any]						={'''x''': 3}
       lowercase       : Tuple						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       # evaluate returns the value of the last assignment.
       assert result == "This is x: 3."
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''text''': '''This is x: 3.'''}		)






      def 					A__   (			self      :		Union[str, Any]		)	->	List[Any]:


       '''simple docstring'''

       lowercase       : Tuple						='''if x <= 3:\n    y = 2\nelse:\n    y = 5'''
       lowercase       : Union[str, Any]						={'''x''': 3}
       lowercase       : Any						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       # evaluate returns the value of the last assignment.
       assert result == 2
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''y''': 2}		)

       lowercase       : Optional[Any]						={'''x''': 8}
       lowercase       : str						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       # evaluate returns the value of the last assignment.
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 8, '''y''': 5}		)






      def 					A__   (			self      :		str		)	->	Optional[Any]:


       '''simple docstring'''

       lowercase       : List[str]						='''test_list = [x, add_two(x)]'''
       lowercase       : Any						={'''x''': 3}
       lowercase       : Tuple						=evaluate(UpperCAmelCase  ,   {'''add_two''': add_two}  ,   state=UpperCAmelCase		)
       self.assertListEqual(UpperCAmelCase  ,   [3, 5]		)
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''test_list''': [3, 5]}		)






      def 					A__   (			self      :		Any		)	->	Tuple:


       '''simple docstring'''

       lowercase       : str						='''y = x'''
       lowercase       : Dict						={'''x''': 3}
       lowercase       : Tuple						=evaluate(UpperCAmelCase  ,   {}  ,   state=UpperCAmelCase		)
       assert result == 3
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''y''': 3}		)






      def 					A__   (			self      :		str		)	->	List[str]:


       '''simple docstring'''

       lowercase       : Any						='''test_list = [x, add_two(x)]\ntest_list[1]'''
       lowercase       : Any						={'''x''': 3}
       lowercase       : Union[str, Any]						=evaluate(UpperCAmelCase  ,   {'''add_two''': add_two}  ,   state=UpperCAmelCase		)
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''test_list''': [3, 5]}		)

       lowercase       : int						='''test_dict = {\'x\': x, \'y\': add_two(x)}\ntest_dict[\'y\']'''
       lowercase       : Union[str, Any]						={'''x''': 3}
       lowercase       : Tuple						=evaluate(UpperCAmelCase  ,   {'''add_two''': add_two}  ,   state=UpperCAmelCase		)
       assert result == 5
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}		)






      def 					A__   (			self      :		List[str]		)	->	Tuple:


       '''simple docstring'''

       lowercase       : Optional[int]						='''x = 0\nfor i in range(3):\n    x = i'''
       lowercase       : List[str]						={}
       lowercase       : Union[str, Any]						=evaluate(UpperCAmelCase  ,   {'''range''': range}  ,   state=UpperCAmelCase		)
       assert result == 2
       self.assertDictEqual(UpperCAmelCase  ,   {'''x''': 2, '''i''': 2}		)



