




'''simple docstring'''

def 						UpperCamelCase    (							_lowerCamelCase : list[list[int]]						,	_lowerCamelCase : int						,	_lowerCamelCase : int						,	_lowerCamelCase : list[int]	):

    # 1. Validate that path exists between current and next vertices
    if graph[path[curr_ind - 1]][next_ver] == 0:
        return False

    # 2. Validate that next vertex is not already in path
    return not any(vertex == next_ver for vertex in path	)





def 						UpperCamelCase    (							_lowerCamelCase : list[list[int]]						,	_lowerCamelCase : list[int]						,	_lowerCamelCase : int	):

    # Base Case
    if curr_ind == len(_lowerCamelCase	):
        # return whether path exists between current and starting vertices
        return graph[path[curr_ind - 1]][path[0]] == 1

    # Recursive Step
    for next_ver in range(0						,	len(_lowerCamelCase	)	):
        if valid_connection(_lowerCamelCase						,	_lowerCamelCase						,	_lowerCamelCase						,	_lowerCamelCase	):
            # Insert current vertex  into path as next transition
            A__    =      next_ver
            # Validate created path
            if util_hamilton_cycle(_lowerCamelCase						,	_lowerCamelCase						,	curr_ind + 1	):
                return True
            # Backtrack
            A__    =      -1
    return False





def 						UpperCamelCase    (							_lowerCamelCase : list[list[int]]						,	_lowerCamelCase : int = 0	):
    A__    =      [-1] * (len(_lowerCamelCase	) + 1)
    # initialize start and end of path with starting index
    A__    =      A__    =      start_index
    # evaluate and if we find answer return path either return empty array
    return path if util_hamilton_cycle(_lowerCamelCase						,	_lowerCamelCase						,	1	) else []










'''simple docstring'''

def 						UpperCamelCase    (							_lowerCamelCase : List[Any]						,	_lowerCamelCase : List[str]						,	_lowerCamelCase : List[str]						,	_lowerCamelCase : Tuple	):
    # Return True if there is node that has not iterated.
    A__    =      [False] * len(_lowerCamelCase	)
    A__    =      []
    queue.append(_lowerCamelCase	)
    A__    =      True

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

    return visited[t]





def 						UpperCamelCase    (							_lowerCamelCase : Optional[Any]						,	_lowerCamelCase : Optional[Any]						,	_lowerCamelCase : Optional[int]	):
    # This array is filled by BFS and to store path
    A__    =      [-1] * (len(_lowerCamelCase	))
    A__    =      0
    while bfs(_lowerCamelCase						,	_lowerCamelCase						,	_lowerCamelCase						,	_lowerCamelCase	):
        A__    =      float("Inf"	)
        A__    =      sink

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

        max_flow += path_flow
        A__    =      sink

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


__lowerCAmelCase							:     Any		     =[
    [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							:     int		     =0, 5



print(ford_fulkerson(graph, source, sink))



