We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
all_node_cuts returns too few and incorrect cuts.
This could be a documentation issue, a bug or a user understanding issue. Are these cases pathological for the algorithm?

Given a square graph:

```
 a -- b
 |    |
 c -- d
```

Based on a cursory reading of the documentation, I would have expected all_node_cuts() to return:

```
[{'a','d'}, {'c','b'}]
```

I get `[{'a','c'}]` but if this is a valid node cut then surely {a,b}, {b,d}, {c,d} are also equally valid and a function called "all node cuts" should return them. 

```
G = nx.Graph([('a','b'), ('a','c'), ('c','d'), ('b','d')])
print( G.nodes() )
print( G.edges() )
print( list(nx.all_node_cuts(G)) )

>>> ['a', 'c', 'b', 'd']
>>> [('a', 'c'), ('a', 'b'), ('c', 'd'), ('b', 'd')]
>>> [{'a', 'c'}]
```

Expanding to a hexagon, we see similar pattern of node cuts. There are many isometric node cuts omitted from the results list. Two of the proposed cuts fail to create "two or more connected components" as the documentation suggests.

```
G = nx.Graph([('a','b'), ('b','c'), ('c','d'),('d','e'), ('e','f'),('f','a')])
list(nx.all_node_cuts(G))
>>> [{'a', 'c'}, {'a', 'b'}, {'b', 'c'}]
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `networkx/algorithms/connectivity/kcutsets.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 Kanevsky all minimum node k cutsets algorithm.
4 """
5 from operator import itemgetter
6 
7 import networkx as nx
8 from .utils import build_auxiliary_node_connectivity
9 from networkx.algorithms.flow import (
10     build_residual_network,
11     edmonds_karp,
12     shortest_augmenting_path,
13 )
14 default_flow_func = edmonds_karp
15 
16 
17 __author__ = '\n'.join(['Jordi Torrents <jtorrents@milnou.net>'])
18 
19 __all__ = ['all_node_cuts']
20 
21 def all_node_cuts(G, k=None, flow_func=None):
22     r"""Returns all minimum k cutsets of an undirected graph G. 
23 
24     This implementation is based on Kanevsky's algorithm [1]_ for finding all
25     minimum-size node cut-sets of an undirected graph G; ie the set (or sets) 
26     of nodes of cardinality equal to the node connectivity of G. Thus if 
27     removed, would break G into two or more connected components.
28    
29     Parameters
30     ----------
31     G : NetworkX graph
32         Undirected graph
33 
34     k : Integer
35         Node connectivity of the input graph. If k is None, then it is 
36         computed. Default value: None.
37 
38     flow_func : function
39         Function to perform the underlying flow computations. Default value
40         edmonds_karp. This function performs better in sparse graphs with
41         right tailed degree distributions. shortest_augmenting_path will
42         perform better in denser graphs.
43         
44 
45     Returns
46     -------
47     cuts : a generator of node cutsets
48         Each node cutset has cardinality equal to the node connectivity of
49         the input graph.
50 
51     Examples
52     --------
53     >>> # A two-dimensional grid graph has 4 cutsets of cardinality 2
54     >>> G = nx.grid_2d_graph(5, 5)
55     >>> cutsets = list(nx.all_node_cuts(G))
56     >>> len(cutsets)
57     4
58     >>> all(2 == len(cutset) for cutset in cutsets)
59     True
60     >>> nx.node_connectivity(G)
61     2
62 
63     Notes
64     -----
65     This implementation is based on the sequential algorithm for finding all
66     minimum-size separating vertex sets in a graph [1]_. The main idea is to
67     compute minimum cuts using local maximum flow computations among a set 
68     of nodes of highest degree and all other non-adjacent nodes in the Graph.
69     Once we find a minimum cut, we add an edge between the high degree
70     node and the target node of the local maximum flow computation to make 
71     sure that we will not find that minimum cut again.
72 
73     See also
74     --------
75     node_connectivity
76     edmonds_karp
77     shortest_augmenting_path
78 
79     References
80     ----------
81     .. [1]  Kanevsky, A. (1993). Finding all minimum-size separating vertex 
82             sets in a graph. Networks 23(6), 533--541.
83             http://onlinelibrary.wiley.com/doi/10.1002/net.3230230604/abstract
84 
85     """
86     if not nx.is_connected(G):
87         raise nx.NetworkXError('Input graph is disconnected.')
88 
89     # Initialize data structures.
90     # Keep track of the cuts already computed so we do not repeat them.
91     seen = []
92     # Even-Tarjan reduction is what we call auxiliary digraph 
93     # for node connectivity.
94     H = build_auxiliary_node_connectivity(G)
95     mapping = H.graph['mapping']
96     R = build_residual_network(H, 'capacity')
97     kwargs = dict(capacity='capacity', residual=R)
98     # Define default flow function
99     if flow_func is None:
100         flow_func = default_flow_func
101     if flow_func is shortest_augmenting_path:
102         kwargs['two_phase'] = True
103     # Begin the actual algorithm
104     # step 1: Find node connectivity k of G
105     if k is None:
106         k = nx.node_connectivity(G, flow_func=flow_func)
107     # step 2: 
108     # Find k nodes with top degree, call it X:
109     X = {n for n, d in sorted(G.degree(), key=itemgetter(1), reverse=True)[:k]}
110     # Check if X is a k-node-cutset
111     if _is_separating_set(G, X):
112         seen.append(X)
113         yield X
114 
115     for x in X:
116         # step 3: Compute local connectivity flow of x with all other
117         # non adjacent nodes in G
118         non_adjacent = set(G) - X - set(G[x])
119         for v in non_adjacent:
120             # step 4: compute maximum flow in an Even-Tarjan reduction H of G
121             # and step:5 build the associated residual network R
122             R = flow_func(H, '%sB' % mapping[x], '%sA' % mapping[v], **kwargs)
123             flow_value = R.graph['flow_value']
124 
125             if flow_value == k:
126                 ## Remove saturated edges form the residual network
127                 saturated_edges = [(u, w, d) for (u, w, d) in
128                                     R.edges(data=True)
129                                     if d['capacity'] == d['flow']]
130                 R.remove_edges_from(saturated_edges)
131                 # step 6: shrink the strongly connected components of 
132                 # residual flow network R and call it L
133                 L = nx.condensation(R)
134                 cmap = L.graph['mapping']
135                 # step 7: Compute antichains of L; they map to closed sets in H
136                 # Any edge in H that links a closed set is part of a cutset
137                 for antichain in nx.antichains(L):
138                     # Nodes in an antichain of the condensation graph of
139                     # the residual network map to a closed set of nodes that
140                     # define a node partition of the auxiliary digraph H.
141                     S = {n for n, scc in cmap.items() if scc in antichain}
142                     # Find the cutset that links the node partition (S,~S) in H
143                     cutset = set()
144                     for u in S:
145                         cutset.update((u, w) for w in H[u] if w not in S)
146                     # The edges in H that form the cutset are internal edges
147                     # (ie edges that represent a node of the original graph G)
148                     node_cut = {H.node[n]['id'] for edge in cutset for n in edge}
149 
150                     if len(node_cut) == k:
151                         if node_cut not in seen:
152                             yield node_cut
153                             seen.append(node_cut)
154                         # Add an edge (x, v) to make sure that we do not
155                         # find this cutset again. This is equivalent
156                         # of adding the edge in the input graph 
157                         # G.add_edge(x, v) and then regenerate H and R:
158                         # Add edges to the auxiliary digraph.
159                         H.add_edge('%sB' % mapping[x], '%sA' % mapping[v],
160                                    capacity=1)
161                         H.add_edge('%sB' % mapping[v], '%sA' % mapping[x],
162                                    capacity=1)
163                         # Add edges to the residual network.
164                         R.add_edge('%sB' % mapping[x], '%sA' % mapping[v],
165                                    capacity=1)
166                         R.add_edge('%sA' % mapping[v], '%sB' % mapping[x],
167                                    capacity=1)
168                         break
169                 # Add again the saturated edges to reuse the residual network
170                 R.add_edges_from(saturated_edges)
171 
172 
173 def _is_separating_set(G, cut):
174     """Assumes that the input graph is connected"""
175     if len(cut) == len(G) - 1:
176         return True
177 
178     H = G.copy(with_data=False)
179     H.remove_nodes_from(cut)
180     if nx.is_connected(H):
181         return False
182     return True
183
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/networkx/algorithms/connectivity/kcutsets.py b/networkx/algorithms/connectivity/kcutsets.py
--- a/networkx/algorithms/connectivity/kcutsets.py
+++ b/networkx/algorithms/connectivity/kcutsets.py
@@ -3,6 +3,7 @@
 Kanevsky all minimum node k cutsets algorithm.
 """
 from operator import itemgetter
+from itertools import combinations
 
 import networkx as nx
 from .utils import build_auxiliary_node_connectivity
@@ -86,6 +87,22 @@
     if not nx.is_connected(G):
         raise nx.NetworkXError('Input graph is disconnected.')
 
+    # Addess some corner cases first.
+    # For cycle graphs
+    if G.order() == G.size():
+        if all(2 == d for n, d in G.degree()):
+            seen = set()
+            for u in G:
+                for v in nx.non_neighbors(G, u):
+                    if (u, v) not in seen and (v, u) not in seen:
+                        yield {v, u}
+                        seen.add((v, u))
+            return
+    # For complete Graphs
+    if nx.density(G) == 1:
+        for cut_set in combinations(G, len(G)-1):
+            yield set(cut_set)
+        return
     # Initialize data structures.
     # Keep track of the cuts already computed so we do not repeat them.
     seen = []

{"golden_diff": "diff --git a/networkx/algorithms/connectivity/kcutsets.py b/networkx/algorithms/connectivity/kcutsets.py\n--- a/networkx/algorithms/connectivity/kcutsets.py\n+++ b/networkx/algorithms/connectivity/kcutsets.py\n@@ -3,6 +3,7 @@\n Kanevsky all minimum node k cutsets algorithm.\n \"\"\"\n from operator import itemgetter\n+from itertools import combinations\n \n import networkx as nx\n from .utils import build_auxiliary_node_connectivity\n@@ -86,6 +87,22 @@\n     if not nx.is_connected(G):\n         raise nx.NetworkXError('Input graph is disconnected.')\n \n+    # Addess some corner cases first.\n+    # For cycle graphs\n+    if G.order() == G.size():\n+        if all(2 == d for n, d in G.degree()):\n+            seen = set()\n+            for u in G:\n+                for v in nx.non_neighbors(G, u):\n+                    if (u, v) not in seen and (v, u) not in seen:\n+                        yield {v, u}\n+                        seen.add((v, u))\n+            return\n+    # For complete Graphs\n+    if nx.density(G) == 1:\n+        for cut_set in combinations(G, len(G)-1):\n+            yield set(cut_set)\n+        return\n     # Initialize data structures.\n     # Keep track of the cuts already computed so we do not repeat them.\n     seen = []\n", "issue": "all_node_cuts returns too few and incorrect cuts.\nThis could be a documentation issue, a bug or a user understanding issue. Are these cases pathological for the algorithm?\n\nGiven a square graph:\n\n```\n a -- b\n |    |\n c -- d\n```\n\nBased on a cursory reading of the documentation, I would have expected all_node_cuts() to return:\n\n```\n[{'a','d'}, {'c','b'}]\n```\n\nI get `[{'a','c'}]` but if this is a valid node cut then surely {a,b}, {b,d}, {c,d} are also equally valid and a function called \"all node cuts\" should return them. \n\n```\nG = nx.Graph([('a','b'), ('a','c'), ('c','d'), ('b','d')])\nprint( G.nodes() )\nprint( G.edges() )\nprint( list(nx.all_node_cuts(G)) )\n\n>>> ['a', 'c', 'b', 'd']\n>>> [('a', 'c'), ('a', 'b'), ('c', 'd'), ('b', 'd')]\n>>> [{'a', 'c'}]\n```\n\nExpanding to a hexagon, we see similar pattern of node cuts. There are many isometric node cuts omitted from the results list. Two of the proposed cuts fail to create \"two or more connected components\" as the documentation suggests.\n\n```\nG = nx.Graph([('a','b'), ('b','c'), ('c','d'),('d','e'), ('e','f'),('f','a')])\nlist(nx.all_node_cuts(G))\n>>> [{'a', 'c'}, {'a', 'b'}, {'b', 'c'}]\n```\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nKanevsky all minimum node k cutsets algorithm.\n\"\"\"\nfrom operator import itemgetter\n\nimport networkx as nx\nfrom .utils import build_auxiliary_node_connectivity\nfrom networkx.algorithms.flow import (\n    build_residual_network,\n    edmonds_karp,\n    shortest_augmenting_path,\n)\ndefault_flow_func = edmonds_karp\n\n\n__author__ = '\\n'.join(['Jordi Torrents <jtorrents@milnou.net>'])\n\n__all__ = ['all_node_cuts']\n\ndef all_node_cuts(G, k=None, flow_func=None):\n    r\"\"\"Returns all minimum k cutsets of an undirected graph G. \n\n    This implementation is based on Kanevsky's algorithm [1]_ for finding all\n    minimum-size node cut-sets of an undirected graph G; ie the set (or sets) \n    of nodes of cardinality equal to the node connectivity of G. Thus if \n    removed, would break G into two or more connected components.\n   \n    Parameters\n    ----------\n    G : NetworkX graph\n        Undirected graph\n\n    k : Integer\n        Node connectivity of the input graph. If k is None, then it is \n        computed. Default value: None.\n\n    flow_func : function\n        Function to perform the underlying flow computations. Default value\n        edmonds_karp. This function performs better in sparse graphs with\n        right tailed degree distributions. shortest_augmenting_path will\n        perform better in denser graphs.\n        \n\n    Returns\n    -------\n    cuts : a generator of node cutsets\n        Each node cutset has cardinality equal to the node connectivity of\n        the input graph.\n\n    Examples\n    --------\n    >>> # A two-dimensional grid graph has 4 cutsets of cardinality 2\n    >>> G = nx.grid_2d_graph(5, 5)\n    >>> cutsets = list(nx.all_node_cuts(G))\n    >>> len(cutsets)\n    4\n    >>> all(2 == len(cutset) for cutset in cutsets)\n    True\n    >>> nx.node_connectivity(G)\n    2\n\n    Notes\n    -----\n    This implementation is based on the sequential algorithm for finding all\n    minimum-size separating vertex sets in a graph [1]_. The main idea is to\n    compute minimum cuts using local maximum flow computations among a set \n    of nodes of highest degree and all other non-adjacent nodes in the Graph.\n    Once we find a minimum cut, we add an edge between the high degree\n    node and the target node of the local maximum flow computation to make \n    sure that we will not find that minimum cut again.\n\n    See also\n    --------\n    node_connectivity\n    edmonds_karp\n    shortest_augmenting_path\n\n    References\n    ----------\n    .. [1]  Kanevsky, A. (1993). Finding all minimum-size separating vertex \n            sets in a graph. Networks 23(6), 533--541.\n            http://onlinelibrary.wiley.com/doi/10.1002/net.3230230604/abstract\n\n    \"\"\"\n    if not nx.is_connected(G):\n        raise nx.NetworkXError('Input graph is disconnected.')\n\n    # Initialize data structures.\n    # Keep track of the cuts already computed so we do not repeat them.\n    seen = []\n    # Even-Tarjan reduction is what we call auxiliary digraph \n    # for node connectivity.\n    H = build_auxiliary_node_connectivity(G)\n    mapping = H.graph['mapping']\n    R = build_residual_network(H, 'capacity')\n    kwargs = dict(capacity='capacity', residual=R)\n    # Define default flow function\n    if flow_func is None:\n        flow_func = default_flow_func\n    if flow_func is shortest_augmenting_path:\n        kwargs['two_phase'] = True\n    # Begin the actual algorithm\n    # step 1: Find node connectivity k of G\n    if k is None:\n        k = nx.node_connectivity(G, flow_func=flow_func)\n    # step 2: \n    # Find k nodes with top degree, call it X:\n    X = {n for n, d in sorted(G.degree(), key=itemgetter(1), reverse=True)[:k]}\n    # Check if X is a k-node-cutset\n    if _is_separating_set(G, X):\n        seen.append(X)\n        yield X\n\n    for x in X:\n        # step 3: Compute local connectivity flow of x with all other\n        # non adjacent nodes in G\n        non_adjacent = set(G) - X - set(G[x])\n        for v in non_adjacent:\n            # step 4: compute maximum flow in an Even-Tarjan reduction H of G\n            # and step:5 build the associated residual network R\n            R = flow_func(H, '%sB' % mapping[x], '%sA' % mapping[v], **kwargs)\n            flow_value = R.graph['flow_value']\n\n            if flow_value == k:\n                ## Remove saturated edges form the residual network\n                saturated_edges = [(u, w, d) for (u, w, d) in\n                                    R.edges(data=True)\n                                    if d['capacity'] == d['flow']]\n                R.remove_edges_from(saturated_edges)\n                # step 6: shrink the strongly connected components of \n                # residual flow network R and call it L\n                L = nx.condensation(R)\n                cmap = L.graph['mapping']\n                # step 7: Compute antichains of L; they map to closed sets in H\n                # Any edge in H that links a closed set is part of a cutset\n                for antichain in nx.antichains(L):\n                    # Nodes in an antichain of the condensation graph of\n                    # the residual network map to a closed set of nodes that\n                    # define a node partition of the auxiliary digraph H.\n                    S = {n for n, scc in cmap.items() if scc in antichain}\n                    # Find the cutset that links the node partition (S,~S) in H\n                    cutset = set()\n                    for u in S:\n                        cutset.update((u, w) for w in H[u] if w not in S)\n                    # The edges in H that form the cutset are internal edges\n                    # (ie edges that represent a node of the original graph G)\n                    node_cut = {H.node[n]['id'] for edge in cutset for n in edge}\n\n                    if len(node_cut) == k:\n                        if node_cut not in seen:\n                            yield node_cut\n                            seen.append(node_cut)\n                        # Add an edge (x, v) to make sure that we do not\n                        # find this cutset again. This is equivalent\n                        # of adding the edge in the input graph \n                        # G.add_edge(x, v) and then regenerate H and R:\n                        # Add edges to the auxiliary digraph.\n                        H.add_edge('%sB' % mapping[x], '%sA' % mapping[v],\n                                   capacity=1)\n                        H.add_edge('%sB' % mapping[v], '%sA' % mapping[x],\n                                   capacity=1)\n                        # Add edges to the residual network.\n                        R.add_edge('%sB' % mapping[x], '%sA' % mapping[v],\n                                   capacity=1)\n                        R.add_edge('%sA' % mapping[v], '%sB' % mapping[x],\n                                   capacity=1)\n                        break\n                # Add again the saturated edges to reuse the residual network\n                R.add_edges_from(saturated_edges)\n\n\ndef _is_separating_set(G, cut):\n    \"\"\"Assumes that the input graph is connected\"\"\"\n    if len(cut) == len(G) - 1:\n        return True\n\n    H = G.copy(with_data=False)\n    H.remove_nodes_from(cut)\n    if nx.is_connected(H):\n        return False\n    return True\n", "path": "networkx/algorithms/connectivity/kcutsets.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nKanevsky all minimum node k cutsets algorithm.\n\"\"\"\nfrom operator import itemgetter\nfrom itertools import combinations\n\nimport networkx as nx\nfrom .utils import build_auxiliary_node_connectivity\nfrom networkx.algorithms.flow import (\n    build_residual_network,\n    edmonds_karp,\n    shortest_augmenting_path,\n)\ndefault_flow_func = edmonds_karp\n\n\n__author__ = '\\n'.join(['Jordi Torrents <jtorrents@milnou.net>'])\n\n__all__ = ['all_node_cuts']\n\ndef all_node_cuts(G, k=None, flow_func=None):\n    r\"\"\"Returns all minimum k cutsets of an undirected graph G. \n\n    This implementation is based on Kanevsky's algorithm [1]_ for finding all\n    minimum-size node cut-sets of an undirected graph G; ie the set (or sets) \n    of nodes of cardinality equal to the node connectivity of G. Thus if \n    removed, would break G into two or more connected components.\n   \n    Parameters\n    ----------\n    G : NetworkX graph\n        Undirected graph\n\n    k : Integer\n        Node connectivity of the input graph. If k is None, then it is \n        computed. Default value: None.\n\n    flow_func : function\n        Function to perform the underlying flow computations. Default value\n        edmonds_karp. This function performs better in sparse graphs with\n        right tailed degree distributions. shortest_augmenting_path will\n        perform better in denser graphs.\n        \n\n    Returns\n    -------\n    cuts : a generator of node cutsets\n        Each node cutset has cardinality equal to the node connectivity of\n        the input graph.\n\n    Examples\n    --------\n    >>> # A two-dimensional grid graph has 4 cutsets of cardinality 2\n    >>> G = nx.grid_2d_graph(5, 5)\n    >>> cutsets = list(nx.all_node_cuts(G))\n    >>> len(cutsets)\n    4\n    >>> all(2 == len(cutset) for cutset in cutsets)\n    True\n    >>> nx.node_connectivity(G)\n    2\n\n    Notes\n    -----\n    This implementation is based on the sequential algorithm for finding all\n    minimum-size separating vertex sets in a graph [1]_. The main idea is to\n    compute minimum cuts using local maximum flow computations among a set \n    of nodes of highest degree and all other non-adjacent nodes in the Graph.\n    Once we find a minimum cut, we add an edge between the high degree\n    node and the target node of the local maximum flow computation to make \n    sure that we will not find that minimum cut again.\n\n    See also\n    --------\n    node_connectivity\n    edmonds_karp\n    shortest_augmenting_path\n\n    References\n    ----------\n    .. [1]  Kanevsky, A. (1993). Finding all minimum-size separating vertex \n            sets in a graph. Networks 23(6), 533--541.\n            http://onlinelibrary.wiley.com/doi/10.1002/net.3230230604/abstract\n\n    \"\"\"\n    if not nx.is_connected(G):\n        raise nx.NetworkXError('Input graph is disconnected.')\n\n    # Addess some corner cases first.\n    # For cycle graphs\n    if G.order() == G.size():\n        if all(2 == d for n, d in G.degree()):\n            seen = set()\n            for u in G:\n                for v in nx.non_neighbors(G, u):\n                    if (u, v) not in seen and (v, u) not in seen:\n                        yield {v, u}\n                        seen.add((v, u))\n            return\n    # For complete Graphs\n    if nx.density(G) == 1:\n        for cut_set in combinations(G, len(G)-1):\n            yield set(cut_set)\n        return\n    # Initialize data structures.\n    # Keep track of the cuts already computed so we do not repeat them.\n    seen = []\n    # Even-Tarjan reduction is what we call auxiliary digraph \n    # for node connectivity.\n    H = build_auxiliary_node_connectivity(G)\n    mapping = H.graph['mapping']\n    R = build_residual_network(H, 'capacity')\n    kwargs = dict(capacity='capacity', residual=R)\n    # Define default flow function\n    if flow_func is None:\n        flow_func = default_flow_func\n    if flow_func is shortest_augmenting_path:\n        kwargs['two_phase'] = True\n    # Begin the actual algorithm\n    # step 1: Find node connectivity k of G\n    if k is None:\n        k = nx.node_connectivity(G, flow_func=flow_func)\n    # step 2: \n    # Find k nodes with top degree, call it X:\n    X = {n for n, d in sorted(G.degree(), key=itemgetter(1), reverse=True)[:k]}\n    # Check if X is a k-node-cutset\n    if _is_separating_set(G, X):\n        seen.append(X)\n        yield X\n\n    for x in X:\n        # step 3: Compute local connectivity flow of x with all other\n        # non adjacent nodes in G\n        non_adjacent = set(G) - X - set(G[x])\n        for v in non_adjacent:\n            # step 4: compute maximum flow in an Even-Tarjan reduction H of G\n            # and step:5 build the associated residual network R\n            R = flow_func(H, '%sB' % mapping[x], '%sA' % mapping[v], **kwargs)\n            flow_value = R.graph['flow_value']\n\n            if flow_value == k:\n                ## Remove saturated edges form the residual network\n                saturated_edges = [(u, w, d) for (u, w, d) in\n                                    R.edges(data=True)\n                                    if d['capacity'] == d['flow']]\n                R.remove_edges_from(saturated_edges)\n                # step 6: shrink the strongly connected components of \n                # residual flow network R and call it L\n                L = nx.condensation(R)\n                cmap = L.graph['mapping']\n                # step 7: Compute antichains of L; they map to closed sets in H\n                # Any edge in H that links a closed set is part of a cutset\n                for antichain in nx.antichains(L):\n                    # Nodes in an antichain of the condensation graph of\n                    # the residual network map to a closed set of nodes that\n                    # define a node partition of the auxiliary digraph H.\n                    S = {n for n, scc in cmap.items() if scc in antichain}\n                    # Find the cutset that links the node partition (S,~S) in H\n                    cutset = set()\n                    for u in S:\n                        cutset.update((u, w) for w in H[u] if w not in S)\n                    # The edges in H that form the cutset are internal edges\n                    # (ie edges that represent a node of the original graph G)\n                    node_cut = {H.node[n]['id'] for edge in cutset for n in edge}\n\n                    if len(node_cut) == k:\n                        if node_cut not in seen:\n                            yield node_cut\n                            seen.append(node_cut)\n                        # Add an edge (x, v) to make sure that we do not\n                        # find this cutset again. This is equivalent\n                        # of adding the edge in the input graph \n                        # G.add_edge(x, v) and then regenerate H and R:\n                        # Add edges to the auxiliary digraph.\n                        H.add_edge('%sB' % mapping[x], '%sA' % mapping[v],\n                                   capacity=1)\n                        H.add_edge('%sB' % mapping[v], '%sA' % mapping[x],\n                                   capacity=1)\n                        # Add edges to the residual network.\n                        R.add_edge('%sB' % mapping[x], '%sA' % mapping[v],\n                                   capacity=1)\n                        R.add_edge('%sA' % mapping[v], '%sB' % mapping[x],\n                                   capacity=1)\n                        break\n                # Add again the saturated edges to reuse the residual network\n                R.add_edges_from(saturated_edges)\n\n\ndef _is_separating_set(G, cut):\n    \"\"\"Assumes that the input graph is connected\"\"\"\n    if len(cut) == len(G) - 1:\n        return True\n\n    H = G.copy(with_data=False)\n    H.remove_nodes_from(cut)\n    if nx.is_connected(H):\n        return False\n    return True\n", "path": "networkx/algorithms/connectivity/kcutsets.py"}]}