make_connected.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include <boost/graph/connected_components.hpp>
  15. #include <boost/graph/make_connected.hpp>
  16. using namespace boost;
  17. int main(int argc, char** argv)
  18. {
  19. typedef adjacency_list
  20. < vecS,
  21. vecS,
  22. undirectedS,
  23. property<vertex_index_t, int>
  24. >
  25. graph;
  26. graph g(11);
  27. add_edge(0,1,g);
  28. add_edge(2,3,g);
  29. add_edge(3,4,g);
  30. add_edge(5,6,g);
  31. add_edge(6,7,g);
  32. add_edge(8,9,g);
  33. add_edge(9,10,g);
  34. add_edge(10,8,g);
  35. std::vector< graph_traits<graph>::vertices_size_type >
  36. component(num_vertices(g));
  37. std::cout << "Before calling make_connected, the graph has "
  38. << connected_components(g, &component[0])
  39. << " connected components" << std::endl;
  40. make_connected(g);
  41. std::cout << "After calling make_connected, the graph has "
  42. << connected_components(g, &component[0])
  43. << " connected components" << std::endl;
  44. return 0;
  45. }