Boost logo

Boost Users :

From: Dmitry Bufistov (dmitry_at_[hidden])
Date: 2006-04-21 05:55:31


Ups, I think this is better.
References:
http://boost.org/libs/graph/doc/connected_components.html
--dima


#include <boost/config.hpp>
#include <boost/graph/graph_traits.hpp> // for boost::graph_traits
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <boost/graph/iteration_macros.hpp>

/**/
struct Node
{
        typedef int vertex_index_t;
        vertex_index_t m_vertex_index;
        static vertex_index_t Node::* svertex_index;
};

Node::vertex_index_t Node::* svertex_index = &Node::m_vertex_index;

struct Boundary
{
        double something;
};

typedef boost::adjacency_list<
   boost::setS, boost::listS, boost::undirectedS,
   Node, Boundary, boost::no_property, boost::setS> Graph;

int main(int argc, char*argv[])
{
        Graph g(5);
        typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
        std::map<vertex_t, int> comps;
        std::map<vertex_t, boost::default_color_type> c_m;
        int num = boost::connected_components(g, boost::make_assoc_property_map(comps),
                boost::color_map(boost::make_assoc_property_map(c_m)));
        std::cout << "Number of cc: " << num << std::endl;
        return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net