code: def _find_sources(graph):
      """
      Determine a minimal set of nodes such that the entire graph is reachable
      """
      # For each connected part of the graph, choose at least
      # one node as a starting point, preferably without a parent
      if graph.is_directed():
          # Choose one node from each SCC with minimum in_degree
          sccs = list(nx.strongly_connected_components(graph))
          # condensing the SCCs forms a dag, the nodes in this graph with
          # 0 in-degree correspond to the SCCs from which the minimum set
          # of nodes from which all other nodes can be reached.
          scc_graph = nx.condensation(graph, sccs)
          supernode_to_nodes = {sn: [] for sn in scc_graph.nodes()}
          # Note: the order of mapping differs between pypy and cpython
          # so we have to loop over graph nodes for consistency
          mapping = scc_graph.graph["mapping"]
          for n in graph.nodes:
              sn = mapping[n]
              supernode_to_nodes[sn].append(n)
          sources = []
          for sn in scc_graph.nodes():
              if scc_graph.in_degree[sn] == 0:
                  scc = supernode_to_nodes[sn]
                  node = min(scc, key=lambda n: graph.in_degree[n])
                  sources.append(node)
      else:
          # For undirected graph, the entire graph will be reachable as
          # long as we consider one node from every connected component
          sources = [
              min(cc, key=lambda n: graph.degree[n])
              for cc in nx.connected_components(graph)
          ]
          sources = sorted(sources, key=lambda n: graph.degree[n])
      return sources
  
imports: import sys
  import warnings
  from collections import defaultdict
  import networkx
  from networkx.utils import open_file
label_desc: Use image node_id 3 for calling a global function with example usage: _find_sources(graph) and returns: sources