boost::connected_components使用详解
在图论中,连通分量是指在无向图G中任意两点间都存在路径,则称为连通图。如果G中任意两点之间不存在路径,则称G为非连通图。连通分量就是一个无向图中的极大连通子图。boost::connected_components是Boost库中用来计算连通分量的函数。
boost::connected_components函数的原型如下:
template <class Graph, class ComponentMap>
typename boost::graph_traits::vertices_size_type
connected_components(const Graph&,
ComponentMap);
其中Graph为模板参数,代表图的类型;ComponentMap是一个映射,将顶点对应到连通分量的编号上。函数返回图中连通分量的数量,也就是连通分量的个数。
例程:
下面是一个使用boost::connected_components的简单例子。
#include <boost/config.hpp>
#include
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
using namespace boost;
int main(int argc, char* argv[]) {
typedef adj