/**
[MST]hdu 2122 Ice_cream’s world III
先一边DFS看图是否联通,然后裸的MST
*/
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
#define N 1024
#define M 10000
vector<int> vec[N];
int f[N],r[N];
struct Edge
{
int u,v,c;
void input()
{
scanf("%d%d%d",&u,&v,&c);
vec[u].push_back(v);
vec[v].push_back(u);
}
}edge[M];
int getF(int x)
{
return x == f[x] ? x : getF(f[x]);
}
void unionSet(int x,int y)
{
if(r[x] > r[y])
f[y] = x;
else
{
f[x] = y;
if(r[x] == r[y])
r[y] ++;
}
}
int vis[N];
int n,m,cnt;
void dfs(int u)
{
vis[u] = 1;
++c
[MST]hdu 2122 Ice_cream’s world III
最新推荐文章于 2020-12-15 10:47:23 发布
该博客介绍了一种解决HDU 2122题目的算法,首先通过DFS检查图是否连通,然后应用裸的最小生成树(MST)策略。代码中使用了C++实现,包括图的结构、并查集和边的排序。算法首先遍历所有节点,标记已访问节点,然后对边按权重排序,最后构建MST并计算总权重。
摘要由CSDN通过智能技术生成