code: def to_vertex_cover(G, matching, top_nodes=None):
      """Returns the minimum vertex cover corresponding to the given maximum
      matching of the bipartite graph `G`.
  
      Parameters
      ----------
      G : NetworkX graph
  
        Undirected bipartite graph
  
      matching : dictionary
  
        A dictionary whose keys are vertices in `G` and whose values are the
        distinct neighbors comprising the maximum matching for `G`, as returned
        by, for example, :func:`maximum_matching`. The dictionary *must*
        represent the maximum matching.
  
      top_nodes : container
  
        Container with all nodes in one bipartite node set. If not supplied
        it will be computed. But if more than one solution exists an exception
        will be raised.
  
      Returns
      -------
      vertex_cover : :class:`set`
  
        The minimum vertex cover in `G`.
  
      Raises
      ------
      AmbiguousSolution
        Raised if the input bipartite graph is disconnected and no container
        with all nodes in one bipartite set is provided. When determining
        the nodes in each bipartite set more than one valid solution is
        possible if the input graph is disconnected.
  
      Notes
      -----
      This function is implemented using the procedure guaranteed by `Konig's
      theorem
      <https://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%28graph_theory%29>`_,
      which proves an equivalence between a maximum matching and a minimum vertex
      cover in bipartite graphs.
  
      Since a minimum vertex cover is the complement of a maximum independent set
      for any graph, one can compute the maximum independent set of a bipartite
      graph this way:
  
      >>> G = nx.complete_bipartite_graph(2, 3)
      >>> matching = nx.bipartite.maximum_matching(G)
      >>> vertex_cover = nx.bipartite.to_vertex_cover(G, matching)
      >>> independent_set = set(G) - vertex_cover
      >>> print(list(independent_set))
      [2, 3, 4]
  
      See :mod:`bipartite documentation <networkx.algorithms.bipartite>`
      for further details on how bipartite graphs are handled in NetworkX.
  
      """
      # This is a Python implementation of the algorithm described at
      # <https://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%28graph_theory%29#Proof>.
      L, R = bipartite_sets(G, top_nodes)
      # Let U be the set of unmatched vertices in the left vertex set.
      unmatched_vertices = set(G) - set(matching)
      U = unmatched_vertices & L
      # Let Z be the set of vertices that are either in U or are connected to U
      # by alternating paths.
      Z = _connected_by_alternating_paths(G, matching, U)
      # At this point, every edge either has a right endpoint in Z or a left
      # endpoint not in Z. This gives us the vertex cover.
      return (L - Z) | (R & Z)
  
file_path: networkx/networkx/algorithms/bipartite/matching.py
imports: import collections
  import itertools
  import networkx
  from networkx.algorithms.bipartite import sets
  from networkx.algorithms.bipartite.matrix import biadjacency_matrix
label_desc: Use image node_id 5 for calling a global function with example usage: to_vertex_cover(G, matching, top_nodes) and returns: unknown