+
    �°³j`"  ã                   óŒ   € R t ^ RIHt ^ RIt^ RIHt ^ RIHt R.t	]P                  ! R]! R4      /RRR	7      RR
 l4       tR tR# )z.
Dinitz' algorithm for maximum flow problems.
)ÚdequeN)Úbuild_residual_network)ÚpairwiseÚdinitzÚcapacityÚinfT)Ú
edge_attrsÚreturns_graphÚpreserve_edge_attrsc                ój   € \        WW#WF4      pRVP                  R&   \        P                  ! V4       V# )aÓ  Find a maximum single-commodity flow using Dinitz' algorithm.

This function returns the residual network resulting after computing
the maximum flow. See below for details about the conventions
NetworkX uses for defining residual networks.

This algorithm has a running time of $O(n^2 m)$ for $n$ nodes and $m$
edges [1]_.


Parameters
----------
G : NetworkX graph
    Edges of the graph are expected to have an attribute called
    'capacity'. If this attribute is not present, the edge is
    considered to have infinite capacity.

s : node
    Source node for the flow.

t : node
    Sink node for the flow.

capacity : string or function (default= 'capacity')
    If this is a string, then edge capacity will be accessed via the
    edge attribute with this key (that is, the capacity of the edge
    joining `u` to `v` will be ``G.edges[u, v][capacity]``). If no
    such edge attribute exists, the capacity of the edge is assumed to
    be infinite.

    If this is a function, the capacity of an edge is the value
    returned by the function. The function must accept exactly three
    positional arguments: the two endpoints of an edge and the
    dictionary of edge attributes for that edge. The function must
    return a number or None to indicate a hidden edge.

residual : NetworkX graph
    Residual network on which the algorithm is to be executed. If None, a
    new residual network is created. Default value: None.

value_only : bool
    If True compute only the value of the maximum flow. This parameter
    will be ignored by this algorithm because it is not applicable.

cutoff : integer, float
    If specified, the algorithm will terminate when the flow value reaches
    or exceeds the cutoff. In this case, it may be unable to immediately
    determine a minimum cut. Default value: None.

Returns
-------
R : NetworkX DiGraph
    Residual network after computing the maximum flow.

Raises
------
NetworkXError
    The algorithm does not support MultiGraph and MultiDiGraph. If
    the input graph is an instance of one of these two classes, a
    NetworkXError is raised.

NetworkXUnbounded
    If the graph has a path of infinite capacity, the value of a
    feasible flow on the graph is unbounded above and the function
    raises a NetworkXUnbounded.

See also
--------
:meth:`maximum_flow`
:meth:`minimum_cut`
:meth:`preflow_push`
:meth:`shortest_augmenting_path`

Notes
-----
The residual network :samp:`R` from an input graph :samp:`G` has the
same nodes as :samp:`G`. :samp:`R` is a DiGraph that contains a pair
of edges :samp:`(u, v)` and :samp:`(v, u)` iff :samp:`(u, v)` is not a
self-loop, and at least one of :samp:`(u, v)` and :samp:`(v, u)` exists
in :samp:`G`.

For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['capacity']`
is equal to the capacity of :samp:`(u, v)` in :samp:`G` if it exists
in :samp:`G` or zero otherwise. If the capacity is infinite,
:samp:`R[u][v]['capacity']` will have a high arbitrary finite value
that does not affect the solution of the problem. This value is stored in
:samp:`R.graph['inf']`. For each edge :samp:`(u, v)` in :samp:`R`,
:samp:`R[u][v]['flow']` represents the flow function of :samp:`(u, v)` and
satisfies :samp:`R[u][v]['flow'] == -R[v][u]['flow']`.

The flow value, defined as the total flow into :samp:`t`, the sink, is
stored in :samp:`R.graph['flow_value']`. If :samp:`cutoff` is not
specified, reachability to :samp:`t` using only edges :samp:`(u, v)` such
that :samp:`R[u][v]['flow'] < R[u][v]['capacity']` induces a minimum
:samp:`s`-:samp:`t` cut.

Examples
--------
>>> from networkx.algorithms.flow import dinitz

The functions that implement flow algorithms and output a residual
network, such as this one, are not imported to the base NetworkX
namespace, so you have to explicitly import them from the flow package.

>>> G = nx.DiGraph()
>>> G.add_edge("x", "a", capacity=3.0)
>>> G.add_edge("x", "b", capacity=1.0)
>>> G.add_edge("a", "c", capacity=3.0)
>>> G.add_edge("b", "c", capacity=5.0)
>>> G.add_edge("b", "d", capacity=4.0)
>>> G.add_edge("d", "e", capacity=2.0)
>>> G.add_edge("c", "y", capacity=2.0)
>>> G.add_edge("e", "y", capacity=3.0)
>>> R = dinitz(G, "x", "y")
>>> flow_value = nx.maximum_flow_value(G, "x", "y")
>>> flow_value
3.0
>>> flow_value == R.graph["flow_value"]
True

References
----------
.. [1] Dinitz' Algorithm: The Original Version and Even's Version.
       2006. Yefim Dinitz. In Theoretical Computer Science. Lecture
       Notes in Computer Science. Volume 3895. pp 218-240.
       https://doi.org/10.1007/11685654_10

r   Ú	algorithm)Údinitz_implÚgraphÚnxÚ_clear_cache)ÚGÚsÚtr   ÚresidualÚ
value_onlyÚcutoffÚRs   &&&&&&& Úd/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/flow/dinitz_alg.pyr   r      s2   € ôH 	�A˜! xÓ8€AØ#€A‡G�GˆKÑÜ‡O‚O�AÔØ€Hó    c                 ó¦  aaaaa€ SV 9  d$   \         P                  ! R \        S4       R24      hSV 9  d$   \         P                  ! R \        S4       R24      hSS8X  d   \         P                  ! R4      hVf   \        W4      pMTpV F%  pWg,          P	                  4        F  p^ VR&   K
  	  K'  	  VP
                  R,          oVf   SpVP                  oVP                  oVVV3R lp	VVVV3R lp
^ pWµ8  dF   V	! 4       pSV9  d   M6V
! V4      pV^,          S8”  d   \         P                  ! R4      hW½,          pKK  W¶P
                  R&   V# )	znode z not in graphz!source and sink are the same nodeÚflowr   c                  óÆ  <€ / p S^ /p\        S^ 3.4      pV'       dÄ   S	V 9   d    V # VP                  4       w  r4SV,          P                  4        FŠ  w  rVVR,          VR,          ,
          ^ 8”  g   K#  WP9   d0   W,          V^,           8X  d   W,          P                  V4       KV  KX  \        V.4      W&   V^,           W&   VP                  WT^,           34       KŒ  	  KË  V # )é    r   r   )r   ÚpopleftÚitemsÚappend)
ÚparentsÚvertex_distÚqueueÚuÚdistÚvÚattrÚR_succr   r   s
          €€€r   Úbreath_first_searchÚ(dinitz_impl.<locals>.breath_first_search´   sË   ø€ ØˆØ˜!�fˆÜ˜˜1�v�h“ˆçØ�GŒ|Øð ˆð —m‘m“o‰GˆAØ! !�9Ÿ?™?Ö,‘�Ø˜
Õ# d¨6¥lÕ2°QÖ6Ø”|Ø&�>¨T°A­XÔ5Ø#�J×-Ñ-¨aÖ0ñ 6ô &+¨A¨3£Z˜™
Ø)-°­˜™ØŸ™ a°­ ]Ö3ó -ð ˆr   c                óŽ  <€ ^ pS	pV.p \        W,          4      ^ 8”  d"   W,          ^ ,          pVP                  V4       MBVP                  4        \        V4      ^ 8X  d    V# VR,          pW,          P                  4        VS8X  Ed8   Sp\	        V4       FB  w  r$\        VSV,          V,          R,          SV,          V,          R,          ,
          4      pKD  	  \	        \        V4      4       F»  w  r$SV,          V,          R;;,          V,          uu&   SV,          V,          R;;,          V,          uu&   SV,          V,          R,          SV,          V,          R,          ,
          ^ 8X  g   K…  W,          P                  4        VR,          V8w  g   K«  VP                  4        K"  	  W,          pVR,          pTpEK¾  )z-Build a path using DFS starting from the sinkr   r   éÿÿÿÿ)Úlenr    Úpopr   r   ÚminÚreversed)
r!   Ú
total_flowr$   Úpathr&   r   ÚINFÚR_predr   r   s
   &     €€€€r   Údepth_first_searchÚ'dinitz_impl.<locals>.depth_first_searchÈ   sb  ø€ ð ˆ
ØˆàˆsˆàÜ�7•:‹ Ô"Ø•J˜q•M�Ø—‘˜A•à—‘”
Ü�t“9 ”>Øð& Ðð% ˜•H�Ø•
×"Ñ"Ô$à�A�vØ�Ü$ TžN‘D�AÜ˜t V¨A¥Y¨q¥\°*Õ%=ÀÀqÅ	È!ÅÈVÕ@TÕ%TÓU’Dñ +ä$¤X¨d£^Ö4‘D�AØ˜1•I˜a•L ×(¨DÕ0Ó(Ø˜1•I˜a•L ×(¨DÕ0Ó(à˜a•y •| JÕ/°&¸µ)¸Aµ,¸vÕ2FÕFÈ!ÖKØ�
×*Ñ*Ô,Ø" 2�h¨!žmØ ŸH™HžJñ 5ð Õ"�
Ø˜•H�Ø‹Ar   z-Infinite capacity path, flow unbounded above.Ú
flow_value)	r   ÚNetworkXErrorÚstrr   Úvaluesr   ÚsuccÚpredÚNetworkXUnbounded)r   r   r   r   r   r   r   r$   Úer)   r5   r7   r!   Ú	this_flowr3   r4   r(   s   &ff&&&        @@@r   r   r   ˜   s>  ü€ Ø�„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=Ø�„zÜ×Ò ¤s¨1£v h¨mÐ<Ó=Ð=ØˆA„vÜ×ÒÐBÓCÐCàÒÜ" 1Ó/‰àˆó ˆØ•—‘–ˆAØˆAˆf‹Ió ñ ð �'‰'�%�.€Cà‚~Øˆà�V‰V€FØ�V‰V€F÷÷("ð "ðH €JØ
Ô
Ù%Ó'ˆØ�GÔØÙ& wÓ/ˆ	Ø�q�=˜3ÔÜ×&Ò&Ð'VÓWÐWØÕŠ
à&‡G�GˆLÑØ€Hr   )r   NFN)Ú__doc__Úcollectionsr   Únetworkxr   Únetworkx.algorithms.flow.utilsr   Únetworkx.utilsr   Ú__all__Ú_dispatchableÚfloatr   r   © r   r   Ú<module>rI      sX   ðñõ ã Ý AÝ #àˆ*€ð ×ÒØ™E %›LÐ)¸ÐSWôóDóðDôN_r   