POJ-2421 Constructing Roads

题目链接:https://vjudge.net/problem/POJ-2421

最小生成树问题,先给出图的邻接矩阵,再给出已经两两相连的点,求最小生成树的花费

把下三角矩阵的边加入边集,已经相连的点用并查集标记,再用Kruskal做就可以了

#include
#include
#include
#include
#include
using namespace std;
const int MAXN=100+10;//点数
const int MAXM=10000+10;//边数
int UF[MAXN];
struct Edge
{
	int u,v,w;
}edge[MAXM];
int tol; //初始化为0 
void addedge(int u,int v,int w)
{
	edge[tol].u=u;
	edge[tol].v=v;
	edge[tol++].w=w;
} 
bool cmp(Edge a,Edge b) 
{
	return a.w


你可能感兴趣的:(POJ-2421 Constructing Roads)