def flow_to_sink(u, flow_in):
    if (u == sink):
        return flow_in
    flow = 0
    for (v, e) in self.edges[u].items():
        cap = e['capacity']
        if ((cap == 0) or (lv[v] <= lv[u])):
            continue
        f = flow_to_sink(v, min(flow_in, cap))
        if (not f):
            continue
        self.edges[u][v]['capacity'] -= f
        if ((v in self.edges) and (u in self.edges[v])):
            self.edges[v][u]['capacity'] += f
        else:
            self.add_edge(v, u, capacity=f)
        flow_in -= f
        flow += f
    return flow
def flow_to_sink(u, flow_in):
    if (u == sink):
        return flow_in
    flow = 0
    for (v, e) in self.edges[u].items():
        cap = e['capacity']
        if ((cap == 0) or (lv[v] <= lv[u])):
            continue
        f = flow_to_sink(v, min(flow_in, cap))
        if (not f):
            continue
        self.edges[u][v]['capacity'] -= f
        if ((v in self.edges) and (u in self.edges[v])):
            self.edges[v][u]['capacity'] += f
        else:
            self.add_edge(v, u, capacity=f)
        flow_in -= f
        flow += f
    return flow