+
    �°³j×=  ã                   óX  € R t ^ RIt^ RIt. R
Ot]P
                  ! RR7      RR l4       tR t]P
                  ! RR7      R 4       t]P
                  ! RR7      R 4       t	]P
                  ! RR7      R 4       t
]P
                  ! RR7      R 4       t]P
                  ! RR7      R	 4       tR# )zTest sequences for graphiness.N)Úgraphsc                ó¦   € VR8X  d   \        \        V 4      4      pV# VR8X  d   \        \        V 4      4      pV# Rp\        P                  ! V4      h)u×  Returns True if sequence is a valid degree sequence.

A degree sequence is valid if some graph can realize it.

Parameters
----------
sequence : list or iterable container
    A sequence of integer node degrees

method : "eg" | "hh"  (default: 'eg')
    The method used to validate the degree sequence.
    "eg" corresponds to the ErdÅ‘s-Gallai algorithm
    [EG1960]_, [choudum1986]_, and
    "hh" to the Havel-Hakimi algorithm
    [havel1955]_, [hakimi1962]_, [CL1996]_.

Returns
-------
valid : bool
    True if the sequence is a valid degree sequence and False if not.

Examples
--------
>>> G = nx.path_graph(4)
>>> sequence = (d for n, d in G.degree())
>>> nx.is_graphical(sequence)
True

To test a non-graphical sequence:
>>> sequence_list = [d for n, d in G.degree()]
>>> sequence_list[-1] += 1
>>> nx.is_graphical(sequence_list)
False

References
----------
.. [EG1960] ErdÅ‘s and Gallai, Mat. Lapok 11 264, 1960.
.. [choudum1986] S.A. Choudum. "A simple proof of the ErdÅ‘s-Gallai theorem on
   graph sequences." Bulletin of the Australian Mathematical Society, 33,
   pp 67-70, 1986. https://doi.org/10.1017/S0004972700002872
.. [havel1955] Havel, V. "A Remark on the Existence of Finite Graphs"
   Casopis Pest. Mat. 80, 477-480, 1955.
.. [hakimi1962] Hakimi, S. "On the Realizability of a Set of Integers as
   Degrees of the Vertices of a Graph." SIAM J. Appl. Math. 10, 496-506, 1962.
.. [CL1996] G. Chartrand and L. Lesniak, "Graphs and Digraphs",
   Chapman and Hall/CRC, 1996.
ÚegÚhhz`method` must be 'eg' or 'hh')Ú%is_valid_degree_sequence_erdos_gallaiÚlistÚ%is_valid_degree_sequence_havel_hakimiÚnxÚNetworkXException)ÚsequenceÚmethodÚvalidÚmsgs   &&  Ú^/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/graphical.pyÚis_graphicalr      sW   € ðb �„~Ü5´d¸8³nÓEˆð €Lð 
�4ŒÜ5´d¸8³nÓEˆð €Lð .ˆÜ×"Ò" 3Ó'Ð'ó    c                 óÂ  € \         P                  P                  V 4      p \        V 4      p^ .V,          p^ V^ ^ 3w  r4rVV  Fe  pV^ 8  g   Wq8¼  d   \         P                  hV^ 8”  g   K)  \        W74      \        WG4      WW,           V^,           3w  r4rVW';;,          ^,          uu&   Kg  	  V^,          '       g   WVV^,
          ,          8”  d   \         P                  hW4WVV3# )é    )r	   ÚutilsÚmake_list_of_intsÚlenÚNetworkXUnfeasibleÚmaxÚmin)Údeg_sequenceÚpÚnum_degsÚdmaxÚdminÚdsumÚnÚds   &       r   Ú_basic_graphical_testsr"   L   sÃ   € ä—8‘8×-Ñ-¨lÓ;€LÜˆLÓ€AØˆs�Q�w€HØ˜Q  1˜*Ñ€D�ÛˆàˆqŒ5�A”FÜ×'Ñ'Ð'à�ŽUÜ"% d£,´°D³¸d½hÈÈAÍÐ"MÑˆD˜Ø�K˜1Õ�Kñ ð ˆa‡x„x�4˜q 1�u�+Ô%Ü×#Ñ#Ð#Ø�t Ð(Ð(r   c                óÊ  €  \        V 4      w  rr4pT^ 8X  g7   ^T,          T,          Y,           ^,           Y,           ^,           ,          8¼  d   R# ^ .T^,           ,          pT^ 8”  dà   YQ,          ^ 8X  d   T^,          pK  Y^,
          8”  d   R# YQ,          ^,
          T^,
          uYQ&   p^ pTp\        T4       FS  p	YX,          ^ 8X  d   T^,          pK  YX,          ^,
          T^,
          uYX&   pT^8”  g   K?  T^,
          Yg&   T^,          pKU  	  \        T4       F&  p	Yi,          p
YZ,          ^,           T^,           uYZ&   pK(  	  Kæ  R#   \        P                   d     R# i ; i)aö  Returns True if deg_sequence can be realized by a simple graph.

The validation proceeds using the Havel-Hakimi theorem
[havel1955]_, [hakimi1962]_, [CL1996]_.
Worst-case run time is $O(s)$ where $s$ is the sum of the sequence.

Parameters
----------
deg_sequence : list
    A list of integers where each element specifies the degree of a node
    in a graph.

Returns
-------
valid : bool
    True if deg_sequence is graphical and False if not.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (4, 2), (5, 1), (5, 4)])
>>> sequence = (d for _, d in G.degree())
>>> nx.is_valid_degree_sequence_havel_hakimi(sequence)
True

To test a non-valid sequence:
>>> sequence_list = [d for _, d in G.degree()]
>>> sequence_list[-1] += 1
>>> nx.is_valid_degree_sequence_havel_hakimi(sequence_list)
False

Notes
-----
The ZZ condition says that for the sequence d if

.. math::
    |d| >= \frac{(\max(d) + \min(d) + 1)^2}{4*\min(d)}

then d is graphical.  This was shown in Theorem 6 in [1]_.

References
----------
.. [1] I.E. Zverovich and V.E. Zverovich. "Contributions to the theory
   of graphic sequences", Discrete Mathematics, 105, pp. 292-303 (1992).
.. [havel1955] Havel, V. "A Remark on the Existence of Finite Graphs"
   Casopis Pest. Mat. 80, 477-480, 1955.
.. [hakimi1962] Hakimi, S. "On the Realizability of a Set of Integers as
   Degrees of the Vertices of a Graph." SIAM J. Appl. Math. 10, 496-506, 1962.
.. [CL1996] G. Chartrand and L. Lesniak, "Graphs and Digraphs",
   Chapman and Hall/CRC, 1996.
FT©r"   r	   r   Úrange)r   r   r   r   r    r   ÚmodstubsÚmslenÚkÚiÚstubs   &          r   r   r   `   sE  € ðhÜ(>¸|Ó(LÑ%ˆ�D˜Xð 	ˆA„v��T•˜A• $¥+°¥/°dµkÀAµoÕ!FÔFÙàˆs�d˜Q•hÕ€Hà
ˆaŒ%à�n Ô!Ø�A�IŠDð �a•%Œ<Ùð %�N¨QÕ.°°AµÐˆ‰˜àˆØˆÜ�t–ˆAØ•+ Ô"Ø�Q•’Ø%�[¨1�_¨a°!­eˆNˆH‰K˜Ø�1ŽuØ"# a¥%�‘Ø˜•
’ñ ô �u–ˆAØ•;ˆDØ (¥°Õ 2°A¸µEÐˆH‰NšAó ñ øôC × Ñ ô Úðús   ‚E	 Å	E"Å!E"c                óª  €  \        V 4      w  rr4pT^ 8X  g7   ^T,          T,          Y,           ^,           Y,           ^,           ,          8¼  d   R# Rw  rgr‰\        Y^,
          R4       FË  p
Y¦^,           8  d    R# YZ,          ^ 8”  g   K"  YZ,          pY¦T,           8  d	   Y¦,
          pY{T
,          ,          p\        T4       F;  pY…Yl,           ,          ,          pY–T,           YVT,           ,          ,          ,          p	K=  	  Yk,          pYvT^,
          ,          Yh,          ,
          T	,           8”  g   KÊ   R# 	  R#   \        P                   d     R# i ; i)u;  Returns True if deg_sequence can be realized by a simple graph.

The validation is done using the ErdÅ‘s-Gallai theorem [EG1960]_.

Parameters
----------
deg_sequence : list
    A list of integers

Returns
-------
valid : bool
    True if deg_sequence is graphical and False if not.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (4, 2), (5, 1), (5, 4)])
>>> sequence = (d for _, d in G.degree())
>>> nx.is_valid_degree_sequence_erdos_gallai(sequence)
True

To test a non-valid sequence:
>>> sequence_list = [d for _, d in G.degree()]
>>> sequence_list[-1] += 1
>>> nx.is_valid_degree_sequence_erdos_gallai(sequence_list)
False

Notes
-----

This implementation uses an equivalent form of the ErdÅ‘s-Gallai criterion.
Worst-case run time is $O(n)$ where $n$ is the length of the sequence.

Specifically, a sequence d is graphical if and only if the
sum of the sequence is even and for all strong indices k in the sequence,

 .. math::

   \sum_{i=1}^{k} d_i \leq k(k-1) + \sum_{j=k+1}^{n} \min(d_i,k)
         = k(n-1) - ( k \sum_{j=0}^{k-1} n_j - \sum_{j=0}^{k-1} j n_j )

A strong index k is any index where d_k >= k and the value n_j is the
number of occurrences of j in d.  The maximal strong index is called the
Durfee index.

This particular rearrangement comes from the proof of Theorem 3 in [2]_.

The ZZ condition says that for the sequence d if

.. math::
    |d| >= \frac{(\max(d) + \min(d) + 1)^2}{4*\min(d)}

then d is graphical.  This was shown in Theorem 6 in [2]_.

References
----------
.. [1] A. Tripathi and S. Vijay. "A note on a theorem of ErdÅ‘s & Gallai",
   Discrete Mathematics, 265, pp. 417-420 (2003).
.. [2] I.E. Zverovich and V.E. Zverovich. "Contributions to the theory
   of graphic sequences", Discrete Mathematics, 105, pp. 292-303 (1992).
.. [EG1960] ErdÅ‘s and Gallai, Mat. Lapok 11 264, 1960.
FT)r   r   r   r   éÿÿÿÿr$   )r   r   r   r   r    r   r(   Úsum_degÚsum_njÚsum_jnjÚdkÚrun_sizeÚvs   &            r   r   r   º   s  € ð@Ü(>¸|Ó(LÑ%ˆ�D˜Xð 	ˆA„v��T•˜A• $¥+°¥/°dµkÀAµoÕ!FÔFÙð #-Ñ€A�Ü�D �( BÖ'ˆØ�A•Œ:ÚØ�<˜!ÖØ•|ˆHØ˜•LÔ Ø�6�Ø "•}Õ$ˆGÜ˜8–_�Ø 1¥5�/Õ)�Ø �E X°!­e¥_Õ4Õ4’ñ %ð �MˆAØ˜a !�e� q¥zÕ1°GÕ;Ö;Úñ (ñ øô- × Ñ ô Úðús   ‚D9 Ä9EÅEc                ó  €  \         P                  P                  V 4      p^ ^ r2T F  pT^ 8  d    R# Y$,           \	        Y44      r2K!  	  T^,          '       g   T^T,          8  d   R# R#   \         P                   d     R# i ; i)a=  Returns True if some multigraph can realize the sequence.

Parameters
----------
sequence : list
    A list of integers

Returns
-------
valid : bool
    True if deg_sequence is a multigraphic degree sequence and False if not.

Examples
--------
>>> G = nx.MultiGraph([(1, 2), (1, 3), (2, 3), (3, 4), (4, 2), (5, 1), (5, 4)])
>>> sequence = (d for _, d in G.degree())
>>> nx.is_multigraphical(sequence)
True

To test a non-multigraphical sequence:
>>> sequence_list = [d for _, d in G.degree()]
>>> sequence_list[-1] += 1
>>> nx.is_multigraphical(sequence_list)
False

Notes
-----
The worst-case run time is $O(n)$ where $n$ is the length of the sequence.

References
----------
.. [1] S. L. Hakimi. "On the realizability of a set of integers as
   degrees of the vertices of a linear graph", J. SIAM, 10, pp. 496-506
   (1962).
FT)r	   r   r   ÚNetworkXErrorr   )r   r   r   r   r!   s   &    r   Úis_multigraphicalr5     s{   € ðJÜ—x‘x×1Ñ1°(Ó;ˆð �Aˆ$ÛˆØˆqŒ5ÚØ•Xœs 4›|Šdñ ð ˆa‡x„x�4˜!˜d�(”?ÙÙøô ×Ñô Úðús   ‚A* Á*BÂBc                óÐ   €  \         P                  P                  V 4      p\	        T4      ^,          ^ 8H  ;'       d    \        T4      ^ 8¬  #   \         P                   d     R# i ; i)aÂ  Returns True if some pseudograph can realize the sequence.

Every nonnegative integer sequence with an even sum is pseudographical
(see [1]_).

Parameters
----------
sequence : list or iterable container
    A sequence of integer node degrees

Returns
-------
valid : bool
  True if the sequence is a pseudographic degree sequence and False if not.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (4, 2), (5, 1), (5, 4)])
>>> sequence = (d for _, d in G.degree())
>>> nx.is_pseudographical(sequence)
True

To test a non-pseudographical sequence:
>>> sequence_list = [d for _, d in G.degree()]
>>> sequence_list[-1] += 1
>>> nx.is_pseudographical(sequence_list)
False

Notes
-----
The worst-case run time is $O(n)$ where n is the length of the sequence.

References
----------
.. [1] F. Boesch and F. Harary. "Line removal algorithms for graphs
   and their degree lists", IEEE Trans. Circuits and Systems, CAS-23(12),
   pp. 778-782 (1976).
F)r	   r   r   r4   Úsumr   )r   r   s   & r   Úis_pseudographicalr8   H  s_   € ðPÜ—x‘x×1Ñ1°(Ó;ˆô ˆ|Ó˜qÕ  AÑ%×@Ð@¬#¨lÓ*;¸qÑ*@Ð@øô ×Ñô Úðús   ‚A ÁA%Á$A%c                óò  €  \         P                  P                  V 4      p\         P                  P                  V4      p^ ^ \	        T4      \	        T4      3w  rErg\        Yg4      p^ p	T^ 8X  d   R# . . rº\        T4       F˜  p^ ^ ríYÇ8  d	   Y<,          pYÆ8  d	   Y,,          pT^ 8  g   T^ 8  d    R# YM,           Y^,           \        Y�4      r•pT^ 8”  d$   T
P                  RT,          RT,          34       Kw  T^ 8”  g   K€  TP                  RT,          4       Kš  	  YE8w  d   R# \        P                  ! T
4       \        P                  ! T4       R.T	^,           ,          pT
'       Eds   \        P                  ! T
4      w  ppTR,          pT\	        T
4      \	        T4      ,           8”  d   R# ^ p\        T4       F™  pT'       d>   T
'       d   T
^ ,          ^ ,          T^ ,          8”  d   \        P                  ! T4      p^ pM\        P                  ! T
4      w  ppT^ 8X  d    R# T^,           ^ 8  g
   T^ 8  g   K‚  T^,           T3TT&   T^,          pK›  	  \        T4       FQ  pTT,          pT^,          ^ 8  d   \        P                  ! T
T4       K3  \        P                  ! TT^ ,          4       KS  	  T^ 8  g   EKa  \        P                  ! TT4       EK{  R#   \         P                   d     R# i ; i)a`  Returns True if some directed graph can realize the in- and out-degree
sequences.

Parameters
----------
in_sequence : list or iterable container
    A sequence of integer node in-degrees

out_sequence : list or iterable container
    A sequence of integer node out-degrees

Returns
-------
valid : bool
  True if in and out-sequences are digraphic False if not.

Examples
--------
>>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 4), (4, 2), (5, 1), (5, 4)])
>>> in_seq = (d for n, d in G.in_degree())
>>> out_seq = (d for n, d in G.out_degree())
>>> nx.is_digraphical(in_seq, out_seq)
True

To test a non-digraphical scenario:
>>> in_seq_list = [d for n, d in G.in_degree()]
>>> in_seq_list[-1] += 1
>>> nx.is_digraphical(in_seq_list, out_seq)
False

Notes
-----
This algorithm is from Kleitman and Wang [1]_.
The worst case runtime is $O(s \times \log n)$ where $s$ and $n$ are the
sum and length of the sequences respectively.

References
----------
.. [1] D.J. Kleitman and D.L. Wang
   Algorithms for Constructing Graphs and Digraphs with Given Valences
   and Factors, Discrete Mathematics, 6(1), pp. 79-88 (1973)
FTr,   )r   r   )r	   r   r   r4   r   r   r%   ÚappendÚheapqÚheapifyÚheappopÚheappush)Úin_sequenceÚout_sequenceÚin_deg_sequenceÚout_deg_sequenceÚsuminÚsumoutÚninÚnoutÚmaxnÚmaxinÚstubheapÚzeroheapr    Úin_degÚout_degr&   ÚfreeoutÚfreeinr'   r)   ÚstuboutÚstubinr*   s   &&                     r   Úis_digraphicalrQ   w  sh  € ðXÜŸ(™(×4Ñ4°[ÓAˆÜŸ8™8×5Ñ5°lÓCÐð
  ! !¤S¨Ó%9¼3Ð?OÓ;PÐPÑ€E�3Üˆs‹>€DØ€EØˆq„yÙØ˜RˆhÜ�4Ž[ˆØ˜Q�ØŒ8Ø&Õ)ˆGØŒ7Ø$Õ'ˆFØ�AŒ:˜ 1œÚØ$�~¨vÕ/?ÄÀUÓAS�uˆØ�AŒ:Ø�O‰O˜R '�\¨2°­;Ð7Ö8Ø�qŽ[Ø�O‰O˜B �LÖ)ñ ð „ÙÜ	‡M‚M�(ÔÜ	‡M‚M�(Ôàˆx˜5 1�9Õ%€Hç
ˆ(ä!ŸMšM¨(Ó3Ñˆ�&Ø�"�ˆØ”C˜“M¤C¨£MÕ1Ô1Ùð ˆÜ�v–ˆAß§¨X°a­[¸­^¸hÀq½kÔ-IÜŸ-š-¨Ó1�Ø‘ä$)§M¢M°(Ó$;Ñ!�˜&Ø˜!Œ|Úà˜�{˜QŒ &¨1¦*Ø#*¨Q¥;°Ð"7�˜‘Ø˜•
’ñ ô �u–ˆAØ˜A•;ˆDØ�A�w˜Œ{Ü—’˜x¨Ö.ä—’˜x¨¨a­Ö1ñ ð �Q�;Ü�NŠN˜8 W×-Ùøô{ ×Ñô Úðús   ‚>K ËK6Ë5K6)r   r5   r8   rQ   r   r   )r   )Ú__doc__r;   Únetworkxr	   Ú__all__Ú_dispatchabler   r"   r   r   r5   r8   rQ   © r   r   Ú<module>rW      sá   ðÙ $ã ã ò€ð ×Ò˜Ôó7ó ð7òt)ð( ×Ò˜ÔñVó ðVðr ×Ò˜ÔñWó ðWðt ×Ò˜Ôñ/ó ð/ðd ×Ò˜Ôñ+Aó ð+Að\ ×Ò˜Ôñkó òkr   