#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 1000 + 10;
struct Edge {
int x, y;
double d;
bool operator < (const Edge& rhs) const {
return d < rhs.d;
}
};
struct MST{
int n, m;//点数和边数
Edge e[maxn*maxn];//储存所有的边
int pa[maxn];//用于并查集,父指针
vector<int> G[maxn];//用于Dfs,储存生成树中每个点相邻的点
vector<double> C[maxn];//用于Dfs,储存相应的边的权
vector<int> nodes;//用于Dfs,储存已经遍历过的节点
double maxcost[maxn][maxn];//储存最小生成树中,u、v唯一路径上的最大权值
//这里是把无根树,转为了有根树,具体做法:
//在初始调用时Dfs(0,-1,0),然后后面节点拓展儿子时,不允许向回走
void dfs(int u, int fa, double facost){
//先对当前点同所有已访问过的节点,进行更新
for(int i = 0; i < nodes.size(); i++) {
int x = nodes[i];
maxcost
“次小生成树类问题”模版
最新推荐文章于 2021-07-06 16:27:20 发布