lemon/connectivity.h
changeset 1184 3c00344f49c9
parent 1091 9eac00ea588f
     1.1 --- a/lemon/connectivity.h	Mon Jul 16 16:21:40 2018 +0200
     1.2 +++ b/lemon/connectivity.h	Wed Oct 17 19:14:07 2018 +0200
     1.3 @@ -2,7 +2,7 @@
     1.4   *
     1.5   * This file is a part of LEMON, a generic C++ optimization library.
     1.6   *
     1.7 - * Copyright (C) 2003-2010
     1.8 + * Copyright (C) 2003-2013
     1.9   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10   * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11   *
    1.12 @@ -745,14 +745,37 @@
    1.13    /// \brief Check whether an undirected graph is bi-node-connected.
    1.14    ///
    1.15    /// This function checks whether the given undirected graph is
    1.16 -  /// bi-node-connected, i.e. any two edges are on same circle.
    1.17 +  /// bi-node-connected, i.e. a connected graph without articulation
    1.18 +  /// node.
    1.19    ///
    1.20    /// \return \c true if the graph bi-node-connected.
    1.21 -  /// \note By definition, the empty graph is bi-node-connected.
    1.22 +  ///
    1.23 +  /// \note By definition,
    1.24 +  /// \li a graph consisting of zero or one node is bi-node-connected,
    1.25 +  /// \li a graph consisting of two isolated nodes
    1.26 +  /// is \e not bi-node-connected and
    1.27 +  /// \li a graph consisting of two nodes connected by an edge
    1.28 +  /// is bi-node-connected.
    1.29    ///
    1.30    /// \see countBiNodeConnectedComponents(), biNodeConnectedComponents()
    1.31    template <typename Graph>
    1.32    bool biNodeConnected(const Graph& graph) {
    1.33 +    bool hasNonIsolated = false, hasIsolated = false;
    1.34 +    for (typename Graph::NodeIt n(graph); n != INVALID; ++n) {
    1.35 +      if (typename Graph::OutArcIt(graph, n) == INVALID) {
    1.36 +        if (hasIsolated || hasNonIsolated) {
    1.37 +          return false;
    1.38 +        } else {
    1.39 +          hasIsolated = true;
    1.40 +        }
    1.41 +      } else {
    1.42 +        if (hasIsolated) {
    1.43 +          return false;
    1.44 +        } else {
    1.45 +          hasNonIsolated = true;
    1.46 +        }
    1.47 +      }
    1.48 +    }
    1.49      return countBiNodeConnectedComponents(graph) <= 1;
    1.50    }
    1.51