def cost_of_flow(G, flowDict, weight='weight'):
 return sum(((flowDict[u][v] * d.get(weight, 0)) for (u, v, d) in G.edges(data=True)))

def cost_of_flow ( G , flowDict , weight = 'weight' ) : return sum ( ( ( flowDict [ u ] [ v ] * d . get ( weight , 0 ) ) for ( u , v , d ) in G . edges ( data = True ) ) )
compute the cost of the flow given by flowdict on graph g .