简体   繁体   中英

C++ Boost Graph Library:- Specifying Root Node for a DFS

Using the standard on a directed graph,

std::vector<size_type> dtime(N);
std::vector<size_type> ftime(N);
size_type t = 0;
dfs_time_visitor<size_type*> vis(&dtime[0], &ftime[0], t);
depth_first_search(graph, visitor(vis));

appears to always start the dfs from node 0.

How does one tell the algorithm to start from a known "root node"?

Here you can find a list of all the overloads for depth_first_search . The one you need is the " named parameter version". The parameter you need to use is "root_vertex" and your invocation of depth_first_search would simply be:

depth_first_search(graph, visitor(vis).root_vertex(root_vertex_descriptor));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM