#include <iostream>
#include<climits>
#include<vector>
#include<windows.h>
#define inf 0x3fffffff
using namespace std;
int n;
int prim(int &v0, vector< vector<int> >&adj);
void init_graph(vector< vector<int> >&adj);
int main()
{
int begin;
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << "please input the number of vertex:";
cin >> n;
vector< vector<int> >A(n, vector<int>(n));
init_graph(A);
cout << "please input begin vertex:";
cin >> begin;
cout << "The weight of minimum tree is " << prim(begin, A) << endl;
system("pause");
return 0;
}
void init_graph(vector< vector<int> >&adj)//对于对称矩阵可优化为只输入上三角和对角线元素
{
cout << "please input " << n << "-order adjacent matrix.\n";
for (int i = 0; i<n; ++i)
for (int j
C++最小生成树Prim算法
最新推荐文章于 2024-04-22 14:07:49 发布