#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1024;
typedef struct Node
{
int s, e, val;
Node(int a, int b, int c)
{
s = a, e = b, val = c;
}
bool operator < (const Node& p) const
{
return p.val > val;
}
};
vector<Node> q;
int p[N];
int find(int x)
{
return x == p[x]? x:find(p[x]);
}
int main(void)
{
int kase;
cin>>kase;
while(kase--)
{
int n, s; //n个点, s条边
cin>>n>>s;
//初始化父节点
for(int i = 0; i < n; i++)
p[i] = i;
for(int i = 0; i < s; i++)
{
int x, y, w; //x起点 y终点 w权值
cin>>x>>y>>w;
q.push_back(Node(x, y, w));
}
sort(q.begin(), q.end());
int s
最小生成树模板(Krustral)
最新推荐文章于 2022-12-21 15:26:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)