
"""simple docstring"""
def    _lowerCAmelCase    (     lowerCamelCase__							:							list[list]				)  ->    list[list]:
  _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = current_set.copy()
  for row_index, row in enumerate(lowerCamelCase__				):
    _SCREAMING_SNAKE_CASE   :				Any							    = row[0]
    for column_index, column in enumerate(lowerCamelCase__				):
      if magnitude == 0:
        _SCREAMING_SNAKE_CASE   :				Optional[int]							    = column
        continue
      _SCREAMING_SNAKE_CASE   :				int							    = column / magnitude
    # Subtract to cancel term
  _SCREAMING_SNAKE_CASE   :				List[Any]							    = current_set[0]
  _SCREAMING_SNAKE_CASE   :				Tuple							    = [first_row]
  _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = current_set[1::]
  for row in current_set:
    _SCREAMING_SNAKE_CASE   :				List[str]							    = []
    # If first term is 0, it is already in form we want, so we preserve it
    if row[0] == 0:
      final_set.append(lowerCamelCase__				)
      continue
    for column_index in range(len(lowerCamelCase__				)				):
      temp_row.append(first_row[column_index] - row[column_index]				)
    final_set.append(lowerCamelCase__				)
  # Create next recursion iteration set
  if len(final_set[0]				) != 3:
    _SCREAMING_SNAKE_CASE   :				Union[str, Any]							    = final_set[0]
    _SCREAMING_SNAKE_CASE   :				int							    = []
    _SCREAMING_SNAKE_CASE   :				Any							    = []
    for row in final_set[1::]:
      current_first_column.append(row[0]				)
      next_iteration.append(row[1::]				)
    _SCREAMING_SNAKE_CASE   :				Optional[int]							    = simplify(lowerCamelCase__				)
    for i in range(len(lowerCamelCase__				)				):
      resultant[i].insert(0,						current_first_column[i]				)
    resultant.insert(0,						lowerCamelCase__				)
    _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = resultant
  return final_set





def    _lowerCAmelCase    (     lowerCamelCase__							:							list[list]				)  ->    list:
  if len(lowerCamelCase__				) == 0:
    raise IndexError("solve_simultaneous() requires n lists of length n+1"				)
  _SCREAMING_SNAKE_CASE   :				int							    = len(lowerCamelCase__				) + 1
  if any(len(lowerCamelCase__				) != _length for item in equations				):
    raise IndexError("solve_simultaneous() requires n lists of length n+1"				)
  for row in equations:
    if any(not isinstance(lowerCamelCase__,						(int, float)				) for column in row				):
      raise ValueError("solve_simultaneous() requires lists of integers"				)
  if len(lowerCamelCase__				) == 1:
    return [equations[0][-1] / equations[0][0]]
  _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = equations.copy()
  if any(0 in row for row in data_set				):
    _SCREAMING_SNAKE_CASE   :				Dict							    = data_set.copy()
    _SCREAMING_SNAKE_CASE   :				int							    = []
    for row_index, row in enumerate(lowerCamelCase__				):
      if 0 not in row:
        _SCREAMING_SNAKE_CASE   :				str							    = data_set.pop(lowerCamelCase__				)
        break
    if not full_row:
      raise ValueError("solve_simultaneous() requires at least 1 full equation"				)
    data_set.insert(0,						lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE   :				List[str]							    = data_set.copy()
  _SCREAMING_SNAKE_CASE   :				Dict							    = simplify(lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE   :				Dict							    = simplified[::-1]
  _SCREAMING_SNAKE_CASE   :				list							    = []
  for row in simplified:
    _SCREAMING_SNAKE_CASE   :				Dict							    = row[-1]
    if not solutions:
      if row[-2] == 0:
        solutions.append(0				)
        continue
      solutions.append(current_solution / row[-2]				)
      continue
    _SCREAMING_SNAKE_CASE   :				str							    = row.copy()[: len(lowerCamelCase__				) - 1 :]
    while temp_row[0] == 0:
      temp_row.pop(0				)
    if len(lowerCamelCase__				) == 0:
      solutions.append(0				)
      continue
    _SCREAMING_SNAKE_CASE   :				List[Any]							    = temp_row[1::]
    _SCREAMING_SNAKE_CASE   :				str							    = temp_row[::-1]
    for column_index, column in enumerate(lowerCamelCase__				):
      current_solution -= column * solutions[column_index]
    solutions.append(lowerCamelCase__				)
  _SCREAMING_SNAKE_CASE   :				Optional[Any]							    = []
  for item in solutions:
    final.append(float(round(lowerCamelCase__,						5				)				)				)
  return final[::-1]


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      lowercase_       :						Optional[int]     					=	[
          [2, 1, 1, 1, 1, 4],
          [1, 2, 1, 1, 1, 5],
          [1, 1, 2, 1, 1, 6],
          [1, 1, 1, 2, 1, 7],
          [1, 1, 1, 1, 2, 8],
      ]
      print(solve_simultaneous(eq))
      print(solve_simultaneous([[4, 2]]))





"""simple docstring"""
def    _lowerCAmelCase    (     lowerCamelCase__							:							str,						lowerCamelCase__							:							str				)  ->    Union[str, Any]:
  print("\nThe shortest path matrix using Floyd Warshall algorithm\n"				)
  for i in range(lowerCamelCase__				):
    for j in range(lowerCamelCase__				):
      if dist[i][j] != float("inf"				):
        print(int(dist[i][j]				),						end="\t"				)
      else:
        print("INF",						end="\t"				)
    print()





def    _lowerCAmelCase    (     lowerCamelCase__							:							Dict,						lowerCamelCase__							:							Any				)  ->    List[str]:
  _SCREAMING_SNAKE_CASE   :				List[Any]							    = [[float("inf"				) for _ in range(lowerCamelCase__				)] for _ in range(lowerCamelCase__				)]

  for i in range(lowerCamelCase__				):
    for j in range(lowerCamelCase__				):
      _SCREAMING_SNAKE_CASE   :				List[Any]							    = graph[i][j]

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

  _print_dist(lowerCamelCase__,						lowerCamelCase__				)
  return dist, v


if __name__ == "__main__":
      lowercase_       :						Tuple     					=	int(input('''Enter number of vertices: '''))
      lowercase_       :						List[Any]     					=	int(input('''Enter number of edges: '''))

      lowercase_       :						Optional[Any]     					=	[[float('''inf''') for i in range(v)] for j in range(v)]

      for i in range(v):
            lowercase_       :						Tuple     					=	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)
            lowercase_       :						str     					=	int(input('''Enter source:'''))
            lowercase_       :						Optional[Any]     					=	int(input('''Enter destination:'''))
            lowercase_       :						Union[str, Any]     					=	float(input('''Enter weight:'''))
            lowercase_       :						str     					=	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



