code: def powerlaw_cluster_graph(n, m, p, seed=None):
      """Holme and Kim algorithm for growing graphs with powerlaw
      degree distribution and approximate average clustering.
  
      Parameters
      ----------
      n : int
          the number of nodes
      m : int
          the number of random edges to add for each new node
      p : float,
          Probability of adding a triangle after adding a random edge
      seed : integer, random_state, or None (default)
          Indicator of random number generation state.
          See :ref:`Randomness<randomness>`.
  
      Notes
      -----
      The average clustering has a hard time getting above a certain
      cutoff that depends on `m`.  This cutoff is often quite low.  The
      transitivity (fraction of triangles to possible triangles) seems to
      decrease with network size.
  
      It is essentially the Barabási–Albert (BA) growth model with an
      extra step that each random edge is followed by a chance of
      making an edge to one of its neighbors too (and thus a triangle).
  
      This algorithm improves on BA in the sense that it enables a
      higher average clustering to be attained if desired.
  
      It seems possible to have a disconnected graph with this algorithm
      since the initial `m` nodes may not be all linked to a new node
      on the first iteration like the BA model.
  
      Raises
      ------
      NetworkXError
          If `m` does not satisfy ``1 <= m <= n`` or `p` does not
          satisfy ``0 <= p <= 1``.
  
      References
      ----------
      .. [1] P. Holme and B. J. Kim,
         "Growing scale-free networks with tunable clustering",
         Phys. Rev. E, 65, 026107, 2002.
      """
  
      if m < 1 or n < m:
          raise nx.NetworkXError(
              f"NetworkXError must have m>1 and m<n, m={m},n={n}"
          )
  
      if p > 1 or p < 0:
          raise nx.NetworkXError(
              f"NetworkXError p must be in [0,1], p={p}"
          )
  
      G = empty_graph(m)  # add m initial nodes (m0 in barabasi-speak)
      repeated_nodes = list(
          G.nodes()
      )  # list of existing nodes to sample from
      # with nodes repeated once for each adjacent edge
      source = m  # next node is m
      while source < n:  # Now add the other n-1 nodes
          possible_targets = _random_subset(repeated_nodes, m, seed)
          # do one preferential attachment for new node
          target = possible_targets.pop()
          G.add_edge(source, target)
          repeated_nodes.append(
              target
          )  # add one node to list for each new link
          count = 1
          while count < m:  # add m-1 more new links
              if seed.random() < p:  # clustering step: add triangle
                  neighborhood = [
                      nbr
                      for nbr in G.neighbors(target)
                      if not G.has_edge(source, nbr) and nbr != source
                  ]
                  if (
                      neighborhood
                  ):  # if there is a neighbor without a link
                      nbr = seed.choice(neighborhood)
                      G.add_edge(source, nbr)  # add triangle
                      repeated_nodes.append(nbr)
                      count = count + 1
                      continue  # go to top of while loop
              # else do preferential attachment step if above fails
              target = possible_targets.pop()
              G.add_edge(source, target)
              repeated_nodes.append(target)
              count = count + 1
  
          repeated_nodes.extend(
              [source] * m
          )  # add source node to list m times
          source += 1
      return G
  
imports: import itertools
  import math
  from collections import defaultdict
  import networkx
  from networkx.utils import py_random_state
  from .classic import complete_graph, empty_graph, path_graph, star_graph
  from .degree_seq import degree_sequence_tree
label_desc: Use image node_id 13 for calling a global function with example usage: powerlaw_cluster_graph(n, m, p, seed) and returns: G