// Output: // The example graph: // a --> b // b --> a c // c --> b // // Vertex a is in component 0 and has root 0 // Vertex b is in component 0 and has root 0 // Vertex c is in component 0 and has root 1 #include #include #include #include #include #include int main(int, char*[]) { using namespace boost; const char* name = "abc"; adjacency_list G; typedef graph_traits >::vertex_descriptor Vertex; Vertex a = add_vertex(G); Vertex b = add_vertex(G); Vertex c = add_vertex(G); add_edge(a, b, G); add_edge(b, a, G); add_edge(c, b, G); add_edge(b, c, G); std::cout << "The example graph:" << std::endl; print_graph(G, name); std::cout << std::endl; std::vector component(num_vertices(G)), discover_time(num_vertices(G)); std::vector color(num_vertices(G)); std::vector root(num_vertices(G)); strong_components(G, make_iterator_property_map(component.begin(), get(vertex_index, G)), root_map(make_iterator_property_map(root.begin(), get(vertex_index, G))). color_map(make_iterator_property_map(color.begin(), get(vertex_index, G))). discover_time_map(make_iterator_property_map(discover_time.begin(), get(vertex_index, G)))); std::vector::size_type i; for (i = 0; i != component.size(); ++i) std::cout << "Vertex " << name[i] << " is in component " << component[i] << " and has root " << root[i] << std::endl; return 0; }