def 					_snake_case	(  __snake_case  ,     __snake_case  ,     __snake_case  ,     __snake_case						):
					# Return True if there is node that has not iterated.
					_UpperCamelCase			     =     [False] * len(__snake_case						)
					_UpperCamelCase			     =     []
					queue.append(__snake_case						)
					_UpperCamelCase			     =     True

					while queue:
										_UpperCamelCase			     =     queue.pop(0						)
										for ind in range(len(graph[u]						)						):
															if visited[ind] is False and graph[u][ind] > 0:
																				queue.append(__snake_case						)
																				_UpperCamelCase			     =     True
																				_UpperCamelCase			     =     u

					return visited[t]
def 					_snake_case	(  __snake_case  ,     __snake_case  ,     __snake_case						):
					# This array is filled by BFS and to store path
					_UpperCamelCase			     =     [-1] * (len(__snake_case						))
					_UpperCamelCase			     =     0
					while bfs(__snake_case  ,     __snake_case  ,     __snake_case  ,     __snake_case						):
										_UpperCamelCase			     =     float('''Inf'''						)
										_UpperCamelCase			     =     sink

										while s != source:
															# Find the minimum value in select path
															_UpperCamelCase			     =     min(__snake_case  ,     graph[parent[s]][s]						)
															_UpperCamelCase			     =     parent[s]

										max_flow += path_flow
										_UpperCamelCase			     =     sink

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


_lowerCAmelCase       =		[
    [0, 16, 13, 0, 0, 0],
    [0, 0, 10, 12, 0, 0],
    [0, 4, 0, 0, 14, 0],
    [0, 0, 9, 0, 0, 20],
    [0, 0, 0, 7, 0, 4],
    [0, 0, 0, 0, 0, 0],
]

_lowerCAmelCase,				_lowerCAmelCase       =		0, 5







print(ford_fulkerson(graph, source, sink))




"""simple docstring"""


import heapq as hq
import math
from collections.abc import Iterator
class     _UpperCamelCase    :
							'''simple docstring'''







							def __init__(	self       ,  __a      ):
										__lowerCAmelCase							       =     str(id_      )
										__lowerCAmelCase							       =     None
										__lowerCAmelCase							       =     None
										__lowerCAmelCase							       =     []
										__lowerCAmelCase							       =     {}  # {vertex:distance}

							def __lt__(	self       ,  __a      ):
										return self.key < other.key

							def __repr__(	self      ):
										return self.id

							def      snake_case							(	self       ,  __a      ):
										self.neighbors.append(__a      )



							def      snake_case							(	self       ,  __a       ,  __a      ):
										__lowerCAmelCase							       =     weight


def _lowerCamelCase      (						_UpperCamelCase       ,					_UpperCamelCase       ,					_UpperCamelCase       ,					_UpperCamelCase ):

			'''simple docstring'''




			graph[a - 1].add_neighbor(graph[b - 1] )
			graph[b - 1].add_neighbor(graph[a - 1] )
			# add the edges:
			graph[a - 1].add_edge(graph[b - 1]       ,					_UpperCamelCase )
			graph[b - 1].add_edge(graph[a - 1]       ,					_UpperCamelCase )


def _lowerCamelCase      (						_UpperCamelCase       ,					_UpperCamelCase ):

			'''simple docstring'''




			__lowerCAmelCase							       =     []
			for u in graph:
						__lowerCAmelCase							       =     math.inf
						__lowerCAmelCase							       =     None
			__lowerCAmelCase							       =     0
			__lowerCAmelCase							       =     graph[:]
			while q:
						__lowerCAmelCase							       =     min(_UpperCamelCase )
						q.remove(_UpperCamelCase )
						for v in u.neighbors:
									if (v in q) and (u.edges[v.id] < v.key):
												__lowerCAmelCase							       =     u
												__lowerCAmelCase							       =     u.edges[v.id]
			for i in range(1       ,					len(_UpperCamelCase ) ):
						a.append((int(graph[i].id ) + 1, int(graph[i].pi.id ) + 1) )
			return a


def _lowerCamelCase      (						_UpperCamelCase       ,					_UpperCamelCase ):

			'''simple docstring'''




			for u in graph:
						__lowerCAmelCase							       =     math.inf
						__lowerCAmelCase							       =     None
			__lowerCAmelCase							       =     0

			__lowerCAmelCase							       =     list(_UpperCamelCase )
			hq.heapify(_UpperCamelCase )

			while h:
						__lowerCAmelCase							       =     hq.heappop(_UpperCamelCase )
						for v in u.neighbors:
									if (v in h) and (u.edges[v.id] < v.key):
												__lowerCAmelCase							       =     u
												__lowerCAmelCase							       =     u.edges[v.id]
												hq.heapify(_UpperCamelCase )

			for i in range(1       ,					len(_UpperCamelCase ) ):
						yield (int(graph[i].id ) + 1, int(graph[i].pi.id ) + 1)


def _lowerCamelCase      (						):

			'''simple docstring'''






if __name__ == "__main__":
	import doctest

	doctest.testmod()




