
    h }                     "   S r SSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
Jr  / SQrS r\R                  " SSS	9S S
 j5       r\R                  " SSS	9S 5       r\R                  " SSS	9S S j5       r\R                  " SSS	9S S j5       r\R                  " SSS	9S S j5       r\R                  " SSS	9\
" S5      S S j5       5       r\R                  " SSS	9S S j5       r\R                  " SSS	9S S j5       r\R                  " SSS	9\
" S5      S S j5       5       r\R                  " SSS	9S S j5       r\R                  " SSS	9\
" S5      SS\4S j5       5       r\R                  " SSS	9S S j5       r\R                  " SSS	9\
" SS/5      S S j5       5       r\R                  " SSS	9S S j5       r\R                  " SSS	9\
" S5      S S j5       5       r\R                  " SSS	9\
" S5      S S j5       5       r\R                  " SSS	9\
" SS/5      S S j5       5       r\R                  " SSS	9S S j5       r \R                  " SSS	9S 5       r!\R                  " SSS	9\
" S5      S S j5       5       r"\R                  " SSS	9S 5       r#g)!a@  Generators for some classic graphs.

The typical graph builder function is called as follows:

>>> G = nx.complete_graph(100)

returning the complete graph on n nodes labeled 0, .., 99
as a simple graph. Except for `empty_graph`, all the functions
in this module return a Graph class (i.e. a simple, undirected graph).

    N)Graph)NetworkXError)nodes_or_numberpairwise)balanced_treebarbell_graphbinomial_treecomplete_graphcomplete_multipartite_graphcircular_ladder_graphcirculant_graphcycle_graph dorogovtsev_goltsev_mendes_graphempty_graphfull_rary_treekneser_graphladder_graphlollipop_graph
null_graph
path_graph
star_graphtadpole_graphtrivial_graphturan_graphwheel_graphc              #   *  #    U S:X  a  g [        [        U 5      5      n[        U5      /nU(       aO  UR                  S5      n[        U5       H%  n [        U5      nUR	                  U5        XF4v   M'     U(       a  MN  g g ! [
         a       M  f = f7f)Nr   )iterrangenextpopappendStopIteration)nrnodesparentssourceitargets          M/var/www/html/env/lib/python3.13/site-packages/networkx/generators/classic.py_tree_edgesr+   3   s     Av qNEE{mG
QqAev&n$	  ' ! s0   AB!B2B?B
BBBBT)graphsreturns_graphc                 P    [        X5      nUR                  [        X5      5        U$ )a:  Creates a full r-ary tree of `n` nodes.

Sometimes called a k-ary, n-ary, or m-ary tree.
"... all non-leaf nodes have exactly r children and all levels
are full except for some rightmost position of the bottom level
(if a leaf at the bottom level is missing, then so are all of the
leaves to its right." [1]_

.. plot::

    >>> nx.draw(nx.full_rary_tree(2, 10))

Parameters
----------
r : int
    branching factor of the tree
n : int
    Number of nodes in the tree
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
G : networkx Graph
    An r-ary tree with n nodes

References
----------
.. [1] An introduction to data structures and algorithms,
       James Andrew Storer,  Birkhauser Boston 2001, (page 225).
)r   add_edges_fromr+   )r$   r#   create_usingGs       r*   r   r   E   s'    B 	A$A[&'H    c                   ^^^ U S::  a  [        S5      eTS::  d  TU :  a  [        S5      e[        R                  " 5       n[        [        R
                  " [        U 5      T5      5      nST-  U :  a  UR                  U5        [        [        U 5      5      m[        R
                  mUR                  UUU4S jU 5       5        U$ )a3  Returns the Kneser Graph with parameters `n` and `k`.

The Kneser Graph has nodes that are k-tuples (subsets) of the integers
between 0 and ``n-1``. Nodes are adjacent if their corresponding sets are disjoint.

Parameters
----------
n: int
    Number of integers from which to make node subsets.
    Subsets are drawn from ``set(range(n))``.
k: int
    Size of the subsets.

Returns
-------
G : NetworkX Graph

Examples
--------
>>> G = nx.kneser_graph(5, 2)
>>> G.number_of_nodes()
10
>>> G.number_of_edges()
15
>>> nx.is_isomorphic(G, nx.petersen_graph())
True
r   zn should be greater than zeroz0k should be greater than zero and smaller than n   c              3   d   >#    U  H%  nT" T[        U5      -
  T5        H  o!U4v   M
     M'     g 7fN)set).0stcombkuniverses      r*   	<genexpr>kneser_graph.<locals>.<genexpr>   s,     QWd8c!f;La6PV6PVW   -0)
r   nxr   list	itertoolscombinationsr   add_nodes_fromr7   r/   )r#   r<   r1   subsetsr;   r=   s    `  @@r*   r   r   k   s    : 	Av;<<AvQNOO

A9))%(A67G1uqy	!58}H!!DQWQQHr2   c                 N    U S:X  a  US-   nOSXS-   -  -
  SU -
  -  n[        XUS9$ )a  Returns the perfectly balanced `r`-ary tree of height `h`.

.. plot::

    >>> nx.draw(nx.balanced_tree(2, 3))

Parameters
----------
r : int
    Branching factor of the tree; each node will have `r`
    children.

h : int
    Height of the tree.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
G : NetworkX graph
    A balanced `r`-ary tree of height `h`.

Notes
-----
This is the rooted tree where all leaves are at distance `h` from
the root. The root has degree `r` and all other internal nodes
have degree `r + 1`.

Node labels are integers, starting from zero.

A balanced tree is also known as a *complete r-ary tree*.

   )r0   )r   )r$   hr0   r#   s       r*   r   r      s=    R 	AvE 1u1q5)!\::r2   c           	        ^ ^ T S:  a  [        S5      eTS:  a  [        S5      e[        T U5      nUR                  5       (       a  [        S5      eUR                  [	        T T T-   S-
  5      5        TS:  a'  UR                  [        [	        T T T-   5      5      5        UR                  U U4S j[	        T T-   ST -  T-   5       5       5        UR                  T S-
  T 5        TS:  a  UR                  T T-   S-
  T T-   5        U$ )a  Returns the Barbell Graph: two complete graphs connected by a path.

.. plot::

    >>> nx.draw(nx.barbell_graph(4, 2))

Parameters
----------
m1 : int
    Size of the left and right barbells, must be greater than 2.

m2 : int
    Length of the path connecting the barbells.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.
   Only undirected Graphs are supported.

Returns
-------
G : NetworkX graph
    A barbell graph.

Notes
-----


Two identical complete graphs $K_{m1}$ form the left and right bells,
and are connected by a path $P_{m2}$.

The `2*m1+m2`  nodes are numbered
    `0, ..., m1-1` for the left barbell,
    `m1, ..., m1+m2-1` for the path,
    and `m1+m2, ..., 2*m1+m2-1` for the right barbell.

The 3 subgraphs are joined via the edges `(m1-1, m1)` and
`(m1+m2-1, m1+m2)`. If `m2=0`, this is merely two complete
graphs joined together.

This graph is an extremal example in David Aldous
and Jim Fill's e-text on Random Walks on Graphs.

r4   z+Invalid graph description, m1 should be >=2r   z+Invalid graph description, m2 should be >=0Directed Graph not supportedrH   c              3   d   >#    U  H%  n[        US -   ST-  T-   5        H  o!U4v   M
     M'     g7f)rH   r4   N)r   )r8   uvm1m2s      r*   r>    barbell_graph.<locals>.<genexpr>	  s4      31U1q5!b&SU+=VA=V3r@   )r   r
   is_directedrE   r   r/   r   add_edge)rO   rP   r0   r1   s   ``  r*   r   r      s    Z 
AvIJJ	AvIJJ 	r<(A}}:;; U2rBw{+,	Av	%BG"456  b2gq2v{3 
 JJrAvr	Av	

27Q;R(Hr2   c                    [         R                  " SU5      nSn[        U 5       HU  nUR                  5        VVs/ s H  u  pVXS-   Xc-   4PM     nnnUR	                  U5        UR                  SU5        US-  nMW     U$ s  snnf )a]  Returns the Binomial Tree of order n.

The binomial tree of order 0 consists of a single node. A binomial tree of order k
is defined recursively by linking two binomial trees of order k-1: the root of one is
the leftmost child of the root of the other.

.. plot::

    >>> nx.draw(nx.binomial_tree(3))

Parameters
----------
n : int
    Order of the binomial tree.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
G : NetworkX graph
    A binomial tree of $2^n$ nodes and $2^n - 1$ edges.

rH   r   r4   )rA   r   r   edgesr/   rS   )r#   r0   r1   Nr(   rM   rN   rU   s           r*   r	   r	     s|    4 	q,'A	A1X./ggi8iFQ!%i8		

1a	Q  H	 9s   B c                     U u  p#[        X15      n[        U5      S:  aU  UR                  5       (       a  [        R                  " US5      nO[        R
                  " US5      nUR                  U5        U$ )aq  Return the complete graph `K_n` with n nodes.

A complete graph on `n` nodes means that all pairs
of distinct nodes have an edge connecting them.

.. plot::

    >>> nx.draw(nx.complete_graph(5))

Parameters
----------
n : int or iterable container of nodes
    If n is an integer, nodes are from range(n).
    If n is a container of nodes, those nodes appear in the graph.
    Warning: n is not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Examples
--------
>>> G = nx.complete_graph(9)
>>> len(G)
9
>>> G.size()
36
>>> G = nx.complete_graph(range(11, 14))
>>> list(G.nodes())
[11, 12, 13]
>>> G = nx.complete_graph(4, nx.DiGraph())
>>> G.is_directed()
True

rH   r4   )r   lenrR   rC   permutationsrD   r/   )r#   r0   _r%   r1   rU   s         r*   r
   r
   ;  sc    J HAE(A
5zA~==??**5!4E**5!4E	Hr2   c                 v    [        X5      nUR                  SU S-
  5        UR                  U SU -  S-
  5        U$ )a  Returns the circular ladder graph $CL_n$ of length n.

$CL_n$ consists of two concentric n-cycles in which
each of the n pairs of concentric nodes are joined by an edge.

Node labels are the integers 0 to n-1

.. plot::

    >>> nx.draw(nx.circular_ladder_graph(5))

r   rH   r4   )r   rS   r#   r0   r1   s      r*   r   r   k  s;     	Q%AJJq!a%JJq!a%!)Hr2   c                     [        X5      n[        U 5       H:  nU H1  nUR                  XDU-
  U -  5        UR                  XDU-   U -  5        M3     M<     U$ )a  Returns the circulant graph $Ci_n(x_1, x_2, ..., x_m)$ with $n$ nodes.

The circulant graph $Ci_n(x_1, ..., x_m)$ consists of $n$ nodes $0, ..., n-1$
such that node $i$ is connected to nodes $(i + x) \mod n$ and $(i - x) \mod n$
for all $x$ in $x_1, ..., x_m$. Thus $Ci_n(1)$ is a cycle graph.

.. plot::

    >>> nx.draw(nx.circulant_graph(10, [1]))

Parameters
----------
n : integer
    The number of nodes in the graph.
offsets : list of integers
    A list of node offsets, $x_1$ up to $x_m$, as described above.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
NetworkX Graph of type create_using

Examples
--------
Many well-known graph families are subfamilies of the circulant graphs;
for example, to create the cycle graph on n points, we connect every
node to nodes on either side (with offset plus or minus one). For n = 10,

>>> G = nx.circulant_graph(10, [1])
>>> edges = [
...     (0, 9),
...     (0, 1),
...     (1, 2),
...     (2, 3),
...     (3, 4),
...     (4, 5),
...     (5, 6),
...     (6, 7),
...     (7, 8),
...     (8, 9),
... ]
>>> sorted(edges) == sorted(G.edges())
True

Similarly, we can create the complete graph
on 5 points with the set of offsets [1, 2]:

>>> G = nx.circulant_graph(5, [1, 2])
>>> edges = [
...     (0, 1),
...     (0, 2),
...     (0, 3),
...     (0, 4),
...     (1, 2),
...     (1, 3),
...     (1, 4),
...     (2, 3),
...     (2, 4),
...     (3, 4),
... ]
>>> sorted(edges) == sorted(G.edges())
True

)r   r   rS   )r#   offsetsr0   r1   r(   js         r*   r   r     sV    F 	A$A1XAJJqq5A+&JJqq5A+&   Hr2   c                 V    U u  p#[        X15      nUR                  [        USS95        U$ )a  Returns the cycle graph $C_n$ of cyclically connected nodes.

$C_n$ is a path with its two end-nodes connected.

.. plot::

    >>> nx.draw(nx.cycle_graph(5))

Parameters
----------
n : int or iterable container of nodes
    If n is an integer, nodes are from `range(n)`.
    If n is a container of nodes, those nodes appear in the graph.
    Warning: n is not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Notes
-----
If create_using is directed, the direction is in increasing order.

Tcyclicr   r/   r   r#   r0   rZ   r%   r1   s        r*   r   r     s/    4 HAE(AXeD12Hr2   c                    U S:  a  [        S5      e[        SU5      nUR                  5       (       a  [        S5      eUR                  5       (       a  [        S5      eUR	                  SS5        Sn[        U 5       HX  n/ nUR                  5        H.  u  pgUR                  Xc45        UR                  Xs45        US-  nM0     UR                  U5        MZ     U$ )a  Returns the hierarchically constructed Dorogovtsev--Goltsev--Mendes graph.

The Dorogovtsev--Goltsev--Mendes [1]_ procedure deterministically produces a
scale-free graph with ``3/2 * (3**(n-1) + 1)`` nodes
and ``3**n`` edges for a given `n`.

Note that `n` denotes the number of times the state transition is applied,
starting from the base graph with ``n = 0`` (no transitions), as in [2]_.
This is different from the parameter ``t = n - 1`` in [1]_.

.. plot::

    >>> nx.draw(nx.dorogovtsev_goltsev_mendes_graph(3))

Parameters
----------
n : integer
    The generation number.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
    Graph type to create. Directed graphs and multigraphs are not supported.

Returns
-------
G : NetworkX `Graph`

Raises
------
NetworkXError
    If `n` is less than zero.

    If `create_using` is a directed graph or multigraph.

Examples
--------
>>> G = nx.dorogovtsev_goltsev_mendes_graph(3)
>>> G.number_of_nodes()
15
>>> G.number_of_edges()
27
>>> nx.is_planar(G)
True

References
----------
.. [1] S. N. Dorogovtsev, A. V. Goltsev and J. F. F. Mendes,
    "Pseudofractal scale-free web", Physical Review E 65, 066122, 2002.
    https://arxiv.org/pdf/cond-mat/0112143.pdf
.. [2] Weisstein, Eric W. "Dorogovtsev--Goltsev--Mendes Graph".
    From MathWorld--A Wolfram Web Resource.
    https://mathworld.wolfram.com/Dorogovtsev-Goltsev-MendesGraph.html
r   z$n must be greater than or equal to 0zdirected graph not supportedzmultigraph not supportedrH   r4   )	r   r   rR   is_multigraphrS   r   rU   r!   r/   )r#   r0   r1   new_noderZ   	new_edgesrM   rN   s           r*   r   r     s    l 	1uBCCA|$A}}:;;677JJq!H1X	GGIDAa]+a]+MH 
 	
#  Hr2   c                     Uc  U" 5       nOK[        U[        5      (       a  U" 5       nO.[        US5      (       d  [        S5      eUR	                  5         UnU u  pEUR                  U5        U$ )a\
  Returns the empty graph with n nodes and zero edges.

.. plot::

    >>> nx.draw(nx.empty_graph(5))

Parameters
----------
n : int or iterable container of nodes (default = 0)
    If n is an integer, nodes are from `range(n)`.
    If n is a container of nodes, those nodes appear in the graph.
create_using : Graph Instance, Constructor or None
    Indicator of type of graph to return.
    If a Graph-type instance, then clear and use it.
    If None, use the `default` constructor.
    If a constructor, call it to create an empty graph.
default : Graph constructor (optional, default = nx.Graph)
    The constructor to use if create_using is None.
    If None, then nx.Graph is used.
    This is used when passing an unknown `create_using` value
    through your home-grown function to `empty_graph` and
    you want a default constructor other than nx.Graph.

Examples
--------
>>> G = nx.empty_graph(10)
>>> G.number_of_nodes()
10
>>> G.number_of_edges()
0
>>> G = nx.empty_graph("ABC")
>>> G.number_of_nodes()
3
>>> sorted(G)
['A', 'B', 'C']

Notes
-----
The variable create_using should be a Graph Constructor or a
"graph"-like object. Constructors, e.g. `nx.Graph` or `nx.MultiGraph`
will be used to create the returned graph. "graph"-like objects
will be cleared (nodes and edges will be removed) and refitted as
an empty "graph" with nodes specified in n. This capability
is useful for specifying the class-nature of the resulting empty
"graph" (i.e. Graph, DiGraph, MyWeirdGraphClass, etc.).

The variable create_using has three main uses:
Firstly, the variable create_using can be used to create an
empty digraph, multigraph, etc.  For example,

>>> n = 10
>>> G = nx.empty_graph(n, create_using=nx.DiGraph)

will create an empty digraph on n nodes.

Secondly, one can pass an existing graph (digraph, multigraph,
etc.) via create_using. For example, if G is an existing graph
(resp. digraph, multigraph, etc.), then empty_graph(n, create_using=G)
will empty G (i.e. delete all nodes and edges using G.clear())
and then add n nodes and zero edges, and return the modified graph.

Thirdly, when constructing your home-grown graph creation function
you can use empty_graph to construct the graph by passing a user
defined create_using to empty_graph. In this case, if you want the
default constructor to be other than nx.Graph, specify `default`.

>>> def mygraph(n, create_using=None):
...     G = nx.empty_graph(n, create_using, nx.MultiGraph)
...     G.add_edges_from([(0, 1), (0, 1)])
...     return G
>>> G = mygraph(3)
>>> G.is_multigraph()
True
>>> G = mygraph(3, nx.Graph)
>>> G.is_multigraph()
False

See also create_empty_copy(G).

adjz;create_using is not a valid NetworkX graph type or instance)
isinstancetypehasattr	TypeErrorclearrE   )r#   r0   defaultr1   rZ   r%   s         r*   r   r   6  sl    f I	L$	'	'N\5))UVV 	HAUHr2   c           	      B  ^  [        ST -  U5      nUR                  5       (       a  [        S5      eUR                  [	        [        T 5      5      5        UR                  [	        [        T ST -  5      5      5        UR                  U 4S j[        T 5       5       5        U$ )zReturns the Ladder graph of length n.

This is two paths of n nodes, with
each pair connected by a single edge.

Node labels are the integers 0 to 2*n - 1.

.. plot::

    >>> nx.draw(nx.ladder_graph(5))

r4   rK   c              3   0   >#    U  H  oUT-   4v   M     g 7fr6    )r8   rN   r#   s     r*   r>   ladder_graph.<locals>.<genexpr>  s     2AQZs   )r   rR   r   r/   r   r   r\   s   `  r*   r   r     s}     	AE<(A}}:;;XeAh'(XeAq1uo./2q22Hr2   rH   c                 F   U u  p[        U5      nUS:  a  [        S5      eUu  p[        U [        R                  5      (       a6  [        U[        R                  5      (       a  [        [        XDU-   5      5      n[        U5      n[        X25      nUR                  5       (       a  [        S5      eUR                  U5        US:  a  UR                  [        U5      5        [        U5      XF-   :w  a  [        S5      eUS:  a  US:  a  UR                  US   US   5        U$ )a<  Returns the Lollipop Graph; ``K_m`` connected to ``P_n``.

This is the Barbell Graph without the right barbell.

.. plot::

    >>> nx.draw(nx.lollipop_graph(3, 4))

Parameters
----------
m, n : int or iterable container of nodes
    If an integer, nodes are from ``range(m)`` and ``range(m, m+n)``.
    If a container of nodes, those nodes appear in the graph.
    Warning: `m` and `n` are not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.

    The nodes for `m` appear in the complete graph $K_m$ and the nodes
    for `n` appear in the path $P_n$
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
Networkx graph
   A complete graph with `m` nodes connected to a path of length `n`.

Notes
-----
The 2 subgraphs are joined via an edge ``(m-1, m)``.
If ``n=0``, this is merely a complete graph.

(This graph is an extremal example in David Aldous and Jim
Fill's etext on Random Walks on Graphs.)

r4   7Invalid description: m should indicate at least 2 nodesrK   rH   z,Nodes must be distinct in containers m and nr   )rX   r   rk   numbersIntegralrB   r   r
   rR   rE   r/   r   rS   )mr#   r0   m_nodesMn_nodesrV   r1   s           r*   r   r     s    L JAGA1uUVVJA!W%%&&:a9I9I+J+JuQA'GA 	w-A}}:;; W1u	'*+
1vJKK 	1uQ	

72;
+Hr2   c                     [        SU 5      nU$ )z^Returns the Null graph with no nodes or edges.

See empty_graph for the use of create_using.

r   r   r0   r1   s     r*   r   r     s     	A|$AHr2   c                 X    U u  p#[        X15      nUR                  [        U5      5        U$ )a  Returns the Path graph `P_n` of linearly connected nodes.

.. plot::

    >>> nx.draw(nx.path_graph(5))

Parameters
----------
n : int or iterable
    If an integer, nodes are 0 to n - 1.
    If an iterable of nodes, in the order they appear in the path.
    Warning: n is not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

rc   rd   s        r*   r   r     s,    ( HAE(AXe_%Hr2   c                 4  ^ U u  p[        U [        R                  5      (       a  UR                  [	        U 5      5        [        X!5      nUR                  5       (       a  [        S5      e[        U5      S:  a  UtmnUR                  U4S jU 5       5        U$ )a  Return the star graph

The star graph consists of one center node connected to n outer nodes.

.. plot::

    >>> nx.draw(nx.star_graph(6))

Parameters
----------
n : int or iterable
    If an integer, node labels are 0 to n with center 0.
    If an iterable of nodes, the center is the first.
    Warning: n is not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Notes
-----
The graph has n+1 nodes for integer n.
So star_graph(3) is the same as star_graph(range(4)).
rK   rH   c              3   ,   >#    U  H	  nTU4v   M     g 7fr6   rs   r8   nodehubs     r*   r>   star_graph.<locals>.<genexpr>;  s     8#t   )
rk   rx   ry   r!   intr   rR   r   rX   r/   )r#   r0   r%   r1   spokesr   s        @r*   r   r     s}    4 HA!W%%&&SVE(A}}:;;
5zA~f	888Hr2   c                    U u  p[        U5      nUS:  a  [        S5      eUu  p[        U [        R                  5      (       a6  [        U[        R                  5      (       a  [        [        XDU-   5      5      n[        X25      nUR                  5       (       a  [        S5      e[        R                  " XcS   /[        U5      -   5        U$ )a  Returns the (m,n)-tadpole graph; ``C_m`` connected to ``P_n``.

This graph on m+n nodes connects a cycle of size `m` to a path of length `n`.
It looks like a tadpole. It is also called a kite graph or a dragon graph.

.. plot::

    >>> nx.draw(nx.tadpole_graph(3, 5))

Parameters
----------
m, n : int or iterable container of nodes
    If an integer, nodes are from ``range(m)`` and ``range(m,m+n)``.
    If a container of nodes, those nodes appear in the graph.
    Warning: `m` and `n` are not checked for duplicates and if present the
    resulting graph may not be as desired.

    The nodes for `m` appear in the cycle graph $C_m$ and the nodes
    for `n` appear in the path $P_n$.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Returns
-------
Networkx graph
   A cycle of size `m` connected to a path of length `n`.

Raises
------
NetworkXError
    If ``m < 2``. The tadpole graph is undefined for ``m<2``.

Notes
-----
The 2 subgraphs are joined via an edge ``(m-1, m)``.
If ``n=0``, this is a cycle graph.
`m` and/or `n` can be a container of nodes instead of an integer.

r4   rv   rK   rw   )rX   r   rk   rx   ry   rB   r   r   rR   rA   add_path)rz   r#   r0   r{   r|   r}   r1   s          r*   r   r   ?  s    T JAGA1uUVVJA!W%%&&:a9I9I+J+JuQA' 	G*A}}:;; KKBK=4=01Hr2   c                     [        SU 5      nU$ )zReturn the Trivial graph with one node (with label 0) and no edges.

.. plot::

    >>> nx.draw(nx.trivial_graph(), with_labels=True)

rH   r   r   s     r*   r   r   }  s     	A|$AHr2   c                     SUs=::  a  U ::  d  O  [        S5      eX-  /XU-  -
  -  X-  S-   /X-  -  -   n[        U6 nU$ )aw  Return the Turan Graph

The Turan Graph is a complete multipartite graph on $n$ nodes
with $r$ disjoint subsets. That is, edges connect each node to
every node not in its subset.

Given $n$ and $r$, we create a complete multipartite graph with
$r-(n \mod r)$ partitions of size $n/r$, rounded down, and
$n \mod r$ partitions of size $n/r+1$, rounded down.

.. plot::

    >>> nx.draw(nx.turan_graph(6, 2))

Parameters
----------
n : int
    The number of nodes.
r : int
    The number of partitions.
    Must be less than or equal to n.

Notes
-----
Must satisfy $1 <= r <= n$.
The graph has $(r-1)(n^2)/(2r)$ edges, rounded down.
rH   zMust satisfy 1 <= r <= n)r   r   )r#   r$   
partitionsr1   s       r*   r   r     sR    < ;Q;677&Qa%[)QVaZLAE,BBJ#Z0AHr2   c                   ^ U u  p#[        X15      nUR                  5       (       a  [        S5      e[        U5      S:  aG  UtmnUR	                  U4S jU 5       5        [        U5      S:  a  UR	                  [        USS95        U$ )av  Return the wheel graph

The wheel graph consists of a hub node connected to a cycle of (n-1) nodes.

.. plot::

    >>> nx.draw(nx.wheel_graph(5))

Parameters
----------
n : int or iterable
    If an integer, node labels are 0 to n with center 0.
    If an iterable of nodes, the center is the first.
    Warning: n is not checked for duplicates and if present the
    resulting graph may not be as desired. Make sure you have no duplicates.
create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

Node labels are the integers 0 to n - 1.
rK   rH   c              3   ,   >#    U  H	  nTU4v   M     g 7fr6   rs   r   s     r*   r>   wheel_graph.<locals>.<genexpr>  s     5#tr   Tra   )r   rR   r   rX   r/   r   )r#   r0   rZ   r%   r1   rimr   s         @r*   r   r     sz    . HAE(A}}:;;
5zA~	c	555s8a<Xc$78Hr2   c                  J   [        5       n[        U 5      S:X  a  U$  [        [        R                  " SU -   5      5      nU VVs/ s H  u  p4[        X45      PM     nnn[        S U  5       5      (       a  [        SU  35      e  [        U5       H  u  pgUR                  XvS9  M     [        R                  " US5       H*  u  pUR                  [        R                  " X5      5        M,     U$ s  snnf ! [         a    U n Nf = f! [         a  n[        S5      UeSnAff = f)	a  Returns the complete multipartite graph with the specified subset sizes.

.. plot::

    >>> nx.draw(nx.complete_multipartite_graph(1, 2, 3))

Parameters
----------
subset_sizes : tuple of integers or tuple of node iterables
   The arguments can either all be integer number of nodes or they
   can all be iterables of nodes. If integers, they represent the
   number of nodes in each subset of the multipartite graph.
   If iterables, each is used to create the nodes for that subset.
   The length of subset_sizes is the number of subsets.

Returns
-------
G : NetworkX Graph
   Returns the complete multipartite graph with the specified subsets.

   For each node, the node attribute 'subset' is an integer
   indicating which subset contains the node.

Examples
--------
Creating a complete tripartite graph, with subsets of one, two, and three
nodes, respectively.

    >>> G = nx.complete_multipartite_graph(1, 2, 3)
    >>> [G.nodes[u]["subset"] for u in G]
    [0, 1, 1, 2, 2, 2]
    >>> list(G.edges(0))
    [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)]
    >>> list(G.edges(2))
    [(2, 0), (2, 3), (2, 4), (2, 5)]
    >>> list(G.edges(4))
    [(4, 0), (4, 1), (4, 2)]

    >>> G = nx.complete_multipartite_graph("a", "bc", "def")
    >>> [G.nodes[u]["subset"] for u in sorted(G)]
    [0, 1, 1, 2, 2, 2]

Notes
-----
This function generalizes several other graph builder functions.

- If no subset sizes are given, this returns the null graph.
- If a single subset size `n` is given, this returns the empty graph on
  `n` nodes.
- If two subset sizes `m` and `n` are given, this returns the complete
  bipartite graph on `m + n` nodes.
- If subset sizes `1` and `n` are given, this returns the star graph on
  `n + 1` nodes.

See also
--------
complete_bipartite_graph
r   )r   c              3   *   #    U  H	  oS :  v   M     g7f)r   Nrs   )r8   sizes     r*   r>   .complete_multipartite_graph.<locals>.<genexpr>  s     1LDaxLs   z$Negative number of nodes not valid: )subsetz+Arguments must be all ints or all iterablesNr4   )r   rX   r   rC   
accumulater   anyr   rn   	enumeraterE   rD   r/   product)subset_sizesr1   extentsstartendrF   r(   r   errsubset1subset2s              r*   r   r     s"   z 	A
<AW9//|0CDE7>?w5$w? 1L111"F|n UVV 2
T"7+IAV. , &227A>	**7<= ?H' @   TIJPSSTs;   'C5 C/C5 #D /C5 5DD
D"DD"r6   )$__doc__rC   rx   networkxrA   networkx.classesr   networkx.exceptionr   networkx.utilsr   r   __all__r+   _dispatchabler   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   r2   r*   <module>r      sn  
    " , 4<$ T2" 3"J T2+ 3+\ T2.; 3.;b T2E 3EP T2" 3"J T2+  3+\ T2 3& T2G 3GT T2  3< T2H 3HV T2$ ^  3^B T2 3, T2!Q>  3>B T2 3 T2  30 T2"  3"J T2!Q9  39x T2	 3	 T2" 3"J T2  3D T2W 3Wr2   