def cut_value(graph, flow, cut):
<EOL>S = []<EOL>T = []<EOL>for node in cut.keys():<EOL><INDENT>if cut[node] == <NUM_LIT:0>:<EOL><INDENT>S.append(node)<EOL><DEDENT>elif cut[node] == <NUM_LIT:1>:<EOL><INDENT>T.append(node)<EOL><DEDENT><DEDENT>value = <NUM_LIT:0><EOL>for node in S:<EOL><INDENT>for neigh in graph.neighbors(node):<EOL><INDENT>if neigh in T:<EOL><INDENT>value = value + flow[(node,neigh)]<EOL><DEDENT><DEDENT>for inc in graph.incidents(node):<EOL><INDENT>if inc in T:<EOL><INDENT>value = value - flow[(inc,node)]    <EOL><DEDENT><DEDENT><DEDENT>return value<EOL>
Calculate the value of a cut.

@type graph: digraph
@param graph: Graph

@type flow: dictionary
@param flow: Dictionary containing a flow for each edge.

@type cut: dictionary
@param cut: Dictionary mapping each node to a subset index. The function only considers the flow between
nodes with 0 and 1.

@rtype: float
@return: The value of the flow between the subsets 0 and 1