1 //=======================================================================
2 // Copyright 2007 Aaron Windsor
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8 #include <iostream>
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/graph/properties.hpp>
11 #include <boost/graph/graph_traits.hpp>
12 #include <boost/property_map/property_map.hpp>
13 #include <vector>
14
15 #include <boost/graph/connected_components.hpp>
16 #include <boost/graph/make_connected.hpp>
17
18 using namespace boost;
19
main(int argc,char ** argv)20 int main(int argc, char** argv)
21 {
22
23 typedef adjacency_list< vecS, vecS, undirectedS,
24 property< vertex_index_t, int > >
25 graph;
26
27 graph g(11);
28 add_edge(0, 1, g);
29 add_edge(2, 3, g);
30 add_edge(3, 4, g);
31 add_edge(5, 6, g);
32 add_edge(6, 7, g);
33 add_edge(8, 9, g);
34 add_edge(9, 10, g);
35 add_edge(10, 8, g);
36
37 std::vector< graph_traits< graph >::vertices_size_type > component(
38 num_vertices(g));
39
40 std::cout << "Before calling make_connected, the graph has "
41 << connected_components(g, &component[0])
42 << " connected components" << std::endl;
43
44 make_connected(g);
45
46 std::cout << "After calling make_connected, the graph has "
47 << connected_components(g, &component[0])
48 << " connected components" << std::endl;
49
50 return 0;
51 }
52