c++中关于图的最小生成树的Prim算法的实现

xiaoxiao2021-02-27  183

最小生成树: 图的所有生成树中具有边上的权值之和最小的树称为图的最小生成树。 最小生成树的准则: 1.必须只使用该图的边来构造最小生成树 2.必须使用且仅使用n-1条边来构造 3.不能使用产生回路的边 代码实现部分: #include #include using namespace std; //邻接矩阵的部分定义: #define MAXV <最大顶点个数> struct MGraph //图的定义 { int edges[MAXV][MAXV]; //邻接矩阵 int n,e; //顶点数,弧数 }; //普里姆算法: #define INF 32767//INF表示∞ void Prim(MGraph g,int v) { int lowcost[MAXV]; int min; int closest[MAXV],i,j,k; for (i=0;i
转载请注明原文地址: https://www.6miu.com/read-11802.html

最新回复(0)