code: def _tree_edges(n, r):
      if n == 0:
          return
      # helper function for trees
      # yields edges in rooted tree at 0 with n nodes and branching ratio r
      nodes = iter(range(n))
      parents = [next(nodes)]  # stack of max length r
      while parents:
          source = parents.pop(0)
          for i in range(r):
              try:
                  target = next(nodes)
                  parents.append(target)
                  yield source, target
              except StopIteration:
                  break
  
imports: import itertools
  import numbers
  import networkx
  from networkx.classes import Graph
  from networkx.exception import NetworkXError
  from networkx.utils import nodes_or_number, pairwise
label_desc: Use image node_id 1 for calling a global function with example usage: _tree_edges(n, r) without return types