【发布时间】:2015-04-19 13:57:42
【问题描述】:
我有点新的 boost 库 (windows 7\visual studio 2010)。我遵循了这个示例代码:
#include <boost/config.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
using namespace std;
int main(int , char* [])
{
using namespace boost;
{
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
Graph G;
add_edge(0, 1, G);
add_edge(1, 4, G);
add_edge(4, 0, G);
add_edge(2, 5, G);
std::vector<int> component(num_vertices(G));
int num = connected_components(G, &component[0]);
std::vector<int>::size_type i;
cout << "Total number of components: " << num << endl;
for (i = 0; i != component.size(); ++i)
cout << "Vertex " << i <<" is in component " << component[i] << endl;
cout << endl;
}
return 0;
}
代码构建图并通过 for 循环打印出哪个顶点属于哪个组件。
有没有一个函数的例子,它得到一个图并返回\存储哪个顶点属于哪个组件-以有组织的方式(某种数据结构)?而不是 for 循环?
我尝试搜索here,希望我没有错过。
谢谢。
编辑: 目标是对每个组件进行测量(例如节点数、直径、一个组件中每个节点的邻居数..)
【问题讨论】:
标签: c++ visual-studio-2010 visual-studio boost