#include
#include
//图(矩阵实现)
#include
#include
#include
//图(链表实现)
#include
//求最小生成树
#include
//prim算法求最小生成树
#include
using namespace std;
using namespace boost;
//顶点名称
enum { A, B, C, D, E, F };
//顶点个数
#define N 6
const char *name = "ABCDEF";
//无向图
void main()
{
//图,每个结点是vec来实现,无向图,有边长与权重的属性
adjacency_list
add_edge(A, B,, myg);
add_edge(B, C, ,myg);
add_edge(A, C,, myg);
add_edge(A, D,, myg);
add_edge(C, D,, myg);
add_edge(B, D,, myg);
//定义图的类型
typedef adjacency\_list<vecS, vecS, undirectedS, property<edge\_weight\_t, int>> mygraph;
//创建边与权重的映射(weight是函数指针)
auto weight= get(edge\_weight,myg);
//property\_map<mygraph, edge\_weight\_t>::type weight = get(edge\_weight, myg);
//vector数组,存放四个顶点
vector<graph\_traits<mygraph>::vertex\_descriptor> pv();
//将最小生成树的结果插到vector中
prim\_minimum\_spanning\_tree(myg, &pv\[\]);
//输出
for (int i = ; i < pv.size(); i++)
{
if (pv\[i\] != i)
{
graph\_traits<mygraph>::edge\_descriptor ed;
bool isok;
//生成绑定
tie(ed, isok) = edge(i, pv\[i\], myg);
cout << "tree" << i << "<--->" << pv\[i\] << " " << weight\[ed\] << endl;
}
}
cin.get();
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章