1 | #include <boost/config.hpp>
|
---|
2 | #include <iostream>
|
---|
3 | #include <vector>
|
---|
4 | #include <boost/graph/strong_components.hpp>
|
---|
5 | #include <boost/graph/adjacency_list.hpp>
|
---|
6 | #include <boost/graph/graph_utility.hpp>
|
---|
7 |
|
---|
8 | int main(int, char*[])
|
---|
9 | {
|
---|
10 | using namespace boost;
|
---|
11 | const char* name = "abc";
|
---|
12 |
|
---|
13 | adjacency_list<vecS, vecS, directedS> G;
|
---|
14 |
|
---|
15 | typedef graph_traits<adjacency_list<vecS, vecS, directedS> >::vertex_descriptor Vertex;
|
---|
16 | Vertex a = add_vertex(G);
|
---|
17 | Vertex b = add_vertex(G);
|
---|
18 | Vertex c = add_vertex(G);
|
---|
19 |
|
---|
20 | add_edge(a, b, G);
|
---|
21 | add_edge(b, a, G);
|
---|
22 |
|
---|
23 | add_edge(c, b, G);
|
---|
24 | add_edge(b, c, G);
|
---|
25 |
|
---|
26 | std::cout << "The example graph:" << std::endl;
|
---|
27 | print_graph(G, name);
|
---|
28 | std::cout << std::endl;
|
---|
29 |
|
---|
30 | std::vector<int> component(num_vertices(G)), discover_time(num_vertices(G));
|
---|
31 | std::vector<default_color_type> color(num_vertices(G));
|
---|
32 | std::vector<Vertex> root(num_vertices(G));
|
---|
33 | strong_components(G, make_iterator_property_map(component.begin(), get(vertex_index, G)),
|
---|
34 | root_map(make_iterator_property_map(root.begin(), get(vertex_index, G))).
|
---|
35 | color_map(make_iterator_property_map(color.begin(), get(vertex_index, G))).
|
---|
36 | discover_time_map(make_iterator_property_map(discover_time.begin(), get(vertex_index, G))));
|
---|
37 |
|
---|
38 | std::vector<int>::size_type i;
|
---|
39 | for (i = 0; i != component.size(); ++i)
|
---|
40 | std::cout << "Vertex " << name[i]
|
---|
41 | << " is in component " << component[i]
|
---|
42 | << " and has root " << root[i] << std::endl;
|
---|
43 |
|
---|
44 | return 0;
|
---|
45 | }
|
---|