






def   _A   (				SCREAMING_SNAKE_CASE__  :	Optional[Any]     ,  SCREAMING_SNAKE_CASE__  :	List[str]       ):
    print('''\nThe shortest path matrix using Floyd Warshall algorithm\n'''       )
    for i in range(UpperCamelCase__       ):
        for j in range(UpperCamelCase__       ):
            if dist[i][j] != float('''inf'''       ):
                print(int(dist[i][j]       )     ,  end='''\t'''       )
            else:
                print('''INF'''     ,  end='''\t'''       )
        print()


def   _A   (				SCREAMING_SNAKE_CASE__  :	Optional[int]     ,  SCREAMING_SNAKE_CASE__  :	str       ):
    UpperCamelCase       :Tuple								=   [[float('''inf'''       ) for _ in range(UpperCamelCase__       )] for _ in range(UpperCamelCase__       )]

    for i in range(UpperCamelCase__       ):
        for j in range(UpperCamelCase__       ):
            UpperCamelCase       :str								=   graph[i][j]

            # check vertex k against all other vertices (i, j)
    for k in range(UpperCamelCase__       ):
        # looping through rows of graph array
        for i in range(UpperCamelCase__       ):
            # looping through columns of graph array
            for j in range(UpperCamelCase__       ):
                if (
                    dist[i][k] != float('''inf'''       )
                    and dist[k][j] != float('''inf'''       )
                    and dist[i][k] + dist[k][j] < dist[i][j]
                ):
                    UpperCamelCase       :List[str]								=   dist[i][k] + dist[k][j]

    _print_dist(UpperCamelCase__     ,  UpperCamelCase__       )
    return dist, v


if __name__ == "__main__":
 __snake_case												=  int(input("""Enter number of vertices: """))
 __snake_case												=  int(input("""Enter number of edges: """))

 __snake_case												=  [[float("""inf""") for i in range(v)] for j in range(v)]

 for i in range(v):
  __snake_case												=  0.0

  # src and dst are indices that must be within the array size graph[e][v]
  # failure to follow this will result in an error
 for i in range(e):
  print("""\nEdge """, i + 1)
  __snake_case												=  int(input("""Enter source:"""))
  __snake_case												=  int(input("""Enter destination:"""))
  __snake_case												=  float(input("""Enter weight:"""))
  __snake_case												=  weight

 floyd_warshall(graph, v)

 # Example Input
 # Enter number of vertices: 3
 # Enter number of edges: 2

 # # generated graph from vertex and edge inputs
 # [[inf, inf, inf], [inf, inf, inf], [inf, inf, inf]]
 # [[0.0, inf, inf], [inf, 0.0, inf], [inf, inf, 0.0]]

 # specify source, destination and weight for edge #1
 # Edge  1
 # Enter source:1
 # Enter destination:2
 # Enter weight:2

 # specify source, destination and weight for edge #2
 # Edge  2
 # Enter source:2
 # Enter destination:1
 # Enter weight:1

 # # Expected Output from the vertice, edge and src, dst, weight inputs!!
 # 0		INF	INF
 # INF	0	2
 # INF	1	0










"""simple docstring"""
from __future__ import annotations

import os
from collections.abc import Mapping

_lowerCAmelCase    :Tuple     =					tuple[int, int]
class 							_UpperCAmelCase							:





     '''simple docstring'''



     def __init__(					self       ,	A       ,	A		)							->					None:
         _UpperCAmelCase							:  set[int]											=    vertices
         _UpperCAmelCase							:  dict[EdgeT, int]											=    {
             (min(A		), max(A		)): weight for edge, weight in edges.items()
         }





     def  __lowerCAmelCase	(					self       ,	A       ,	A		)							->					None:
         self.vertices.add(edge[0]		)
         self.vertices.add(edge[1]		)
         _UpperCAmelCase							:  List[Any]											=    weight





     def  __lowerCAmelCase	(					self		)							->					Graph:
         _UpperCAmelCase							:  Graph											=    Graph({min(self.vertices		)}       ,	{}		)
         _UpperCAmelCase							:  EdgeT
         _UpperCAmelCase							:  int
         _UpperCAmelCase							:  EdgeT
         _UpperCAmelCase							:  int

         while len(subgraph.vertices		) < len(self.vertices		):
             _UpperCAmelCase							:  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:
                         _UpperCAmelCase							:  Tuple											=    edge
                         _UpperCAmelCase							:  Optional[int]											=    weight

             subgraph.add_edge(A       ,	A		)

         return subgraph





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

    with open(UpperCamelCase__							) as f:
        _UpperCAmelCase							:  str											=    f.read().strip().split('''\n'''							)

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

    for edgea in range(1     ,       len(UpperCamelCase__							)							):
        for edgea in range(UpperCamelCase__							):
            if adjaceny_matrix[edgea][edgea] != "-":
                _UpperCAmelCase							:  Optional[Any]											=    int(adjaceny_matrix[edgea][edgea]							)

    _UpperCAmelCase							:  Graph											=    Graph(set(range(len(UpperCamelCase__							)							)							)     ,       UpperCamelCase__							)

    _UpperCAmelCase							:  Graph											=    graph.prims_algorithm()

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

    return initial_total - optimal_total


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


