def min_weighted_vertex_cover(G, weight=None):
 cost = dict(G.nodes(data=weight, default=1))
 for (u, v) in G.edges():
  min_cost = min(cost[u], cost[v])
  cost[u] -= min_cost
  cost[v] -= min_cost
 return {u for (u, c) in cost.items() if (c == 0)}

def min_weighted_vertex_cover ( G , weight = None ) : cost = dict ( G . nodes ( data = weight , default = 1 ) ) for ( u , v ) in G . edges ( ) : min_cost = min ( cost [ u ] , cost [ v ] ) cost [ u ] -= min_cost cost [ v ] -= min_cost return { u for ( u , c ) in cost . items ( ) if ( c == 0 ) }
returns an approximate minimum weighted vertex cover .