def maximal_matching(G):
 matching = set()
 nodes = set()
 for (u, v) in G.edges():
  if ((u not in nodes) and (v not in nodes) and (u != v)):
   matching.add((u, v))
   nodes.add(u)
   nodes.add(v)
 return matching

def maximal_matching ( G ) : matching = set ( ) nodes = set ( ) for ( u , v ) in G . edges ( ) : if ( ( u not in nodes ) and ( v not in nodes ) and ( u != v ) ) : matching . add ( ( u , v ) ) nodes . add ( u ) nodes . add ( v ) return matching
find a maximal matching in the graph .