
'''simple docstring'''







def  snake_case_		(    __SCREAMING_SNAKE_CASE :			int				,				__SCREAMING_SNAKE_CASE :			List[str]				,				__SCREAMING_SNAKE_CASE :			int				,				__SCREAMING_SNAKE_CASE :			Tuple							):



      """simple docstring"""





      lowercase_     :					int													=	[False] * len(A_							)
      lowercase_     :					List[str]													=	[]
      queue.append(A_							)
      lowercase_     :					Dict													=	True

      while queue:
            lowercase_     :					Dict													=	queue.pop(0							)
            for ind in range(len(graph[u]							)							):
                  if visited[ind] is False and graph[u][ind] > 0:
                        queue.append(A_							)
                        lowercase_     :					List[Any]													=	True
                        lowercase_     :					Any													=	u

      return visited[t]
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			Any				,				__SCREAMING_SNAKE_CASE :			Any				,				__SCREAMING_SNAKE_CASE :			Union[str, Any]							):



      """simple docstring"""





      lowercase_     :					str													=	[-1] * (len(A_							))
      lowercase_     :					Optional[Any]													=	0
      while bfs(A_				,				A_				,				A_				,				A_							):
            lowercase_     :					Any													=	float('''Inf'''							)
            lowercase_     :					Optional[int]													=	sink

            while s != source:
                  # Find the minimum value in select path
                  lowercase_     :					Any													=	min(A_				,				graph[parent[s]][s]							)
                  lowercase_     :					Optional[Any]													=	parent[s]

            max_flow += path_flow
            lowercase_     :					str													=	sink

            while v != source:
                  lowercase_     :					int													=	parent[v]
                  graph[u][v] -= path_flow
                  graph[v][u] += path_flow
                  lowercase_     :					Optional[int]													=	parent[v]
      return max_flow


_lowercase			:  Optional[int]   							=	[
    [0, 1_6, 1_3, 0, 0, 0],
    [0, 0, 1_0, 1_2, 0, 0],
    [0, 4, 0, 0, 1_4, 0],
    [0, 0, 9, 0, 0, 2_0],
    [0, 0, 0, 7, 0, 4],
    [0, 0, 0, 0, 0, 0],
]

_lowercase			:  Tuple   							=	0, 5




print(ford_fulkerson(graph, source, sink))





'''simple docstring'''







from __future__ import annotations

from typing import Any






class 			lowerCAmelCase__       :






					def __init__(       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_     :					str													=	num_of_nodes
											lowercase_     :					list[list[int]]													=	[]
											lowercase_     :					dict[int, int]													=	{}






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											self.m_edges.append([u_node, v_node, weight]		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





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






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if self.m_component[u_node] != u_node:
																	for k in self.m_component:
																							lowercase_     :					Optional[int]													=	self.find_component(__SCREAMING_SNAKE_CASE		)






					def      _snake_case   (       self    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if component_size[u_node] <= component_size[v_node]:
																	lowercase_     :					Any													=	v_node
																	component_size[v_node] += component_size[u_node]
																	self.set_component(__SCREAMING_SNAKE_CASE		)

											elif component_size[u_node] >= component_size[v_node]:
																	lowercase_     :					int													=	self.find_component(__SCREAMING_SNAKE_CASE		)
																	component_size[u_node] += component_size[v_node]
																	self.set_component(__SCREAMING_SNAKE_CASE		)






					def      _snake_case   (       self		):


											"""simple docstring"""





											lowercase_     :					Dict													=	[]
											lowercase_     :					Optional[Any]													=	0

											lowercase_     :					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		)

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

											while num_of_components > 1:
																	for edge in self.m_edges:
																							lowercase_						,			lowercase_						,			lowercase_     :					List[Any]													=	edge

																							lowercase_     :					Dict													=	self.m_component[u]
																							lowercase_     :					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
																																			):
																																									lowercase_     :					Union[str, Any]													=	[u, v, w]

																	for edge in minimum_weight_edge:
																							if isinstance(__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE		):
																													lowercase_						,			lowercase_						,			lowercase_     :					str													=	edge

																													lowercase_     :					Tuple													=	self.m_component[u]
																													lowercase_     :					Union[str, Any]													=	self.m_component[v]

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

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







def  snake_case_		(    ):



						"""simple docstring"""







if __name__ == "__main__":
							import doctest

							doctest.testmod()



