# HG changeset patch # User Balazs Dezso # Date 1375995370 -7200 # Node ID 552e3d1242c641658cdb188d4efe452404fb5f22 # Parent 3e711ee55d3184a42ccc00feb76ca15a724b3c88 Fix biNodeConnected() function (#439) diff -r 3e711ee55d31 -r 552e3d1242c6 lemon/connectivity.h --- a/lemon/connectivity.h Wed Aug 07 06:29:34 2013 +0200 +++ b/lemon/connectivity.h Thu Aug 08 22:56:10 2013 +0200 @@ -744,8 +744,9 @@ /// /// \brief Check whether an undirected graph is bi-node-connected. /// - /// This function checks whether the given undirected graph is - /// bi-node-connected, i.e. any two edges are on same circle. + /// This function checks whether the given undirected graph is + /// bi-node-connected, i.e. a connected graph without articulation + /// node. /// /// \return \c true if the graph bi-node-connected. /// \note By definition, the empty graph is bi-node-connected. @@ -753,6 +754,22 @@ /// \see countBiNodeConnectedComponents(), biNodeConnectedComponents() template bool biNodeConnected(const Graph& graph) { + bool hasNonIsolated = false, hasIsolated = false; + for (typename Graph::NodeIt n(graph); n != INVALID; ++n) { + if (typename Graph::OutArcIt(graph, n) == INVALID) { + if (hasIsolated || hasNonIsolated) { + return false; + } else { + hasIsolated = true; + } + } else { + if (hasIsolated) { + return false; + } else { + hasNonIsolated = true; + } + } + } return countBiNodeConnectedComponents(graph) <= 1; } diff -r 3e711ee55d31 -r 552e3d1242c6 test/connectivity_test.cc --- a/test/connectivity_test.cc Wed Aug 07 06:29:34 2013 +0200 +++ b/test/connectivity_test.cc Thu Aug 08 22:56:10 2013 +0200 @@ -99,6 +99,23 @@ } { + ListGraph g; + ListGraph::NodeMap map(g); + + ListGraph::Node n1 = g.addNode(); + ListGraph::Node n2 = g.addNode(); + + ListGraph::Edge e1 = g.addEdge(n1, n2); + ::lemon::ignore_unused_variable_warning(e1); + check(biNodeConnected(g), "Graph is bi-node-connected"); + + ListGraph::Node n3 = g.addNode(); + ::lemon::ignore_unused_variable_warning(n3); + check(!biNodeConnected(g), "Graph is not bi-node-connected"); + } + + + { Digraph d; Digraph::NodeMap order(d); Graph g(d);