文章

71

粉丝

97

获赞

5

访问

18.6k

头像
1341 为什么80%
我要提问
发布于2024年2月8日 12:23
阅读数 263

#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1000 + 5;
int f[maxn];
int height[maxn];
struct node{
    int u, v, w;
}edge[maxn*maxn];

int find(int x) {
    if (x == f[x]) return x;
    f[x] = find(f[x]);
    return f[x];
}

void Union(int fx,int fy) {
    int x = find(fx);
    int y = find(fy);
    if(x!=y){
        if (height[x] > height[y])
        f[y] = x;
    else if(height[x] < height[y])
        f[x] = y;
    else {
        f[x] = y;
        height[y]++;
    }
    }
    
}
int cmp(node x,node y) {
    return x.w < y.w;
}
int main() {
   &...

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年2月8日 15:09

edge存储的下标从0开始

赞(0)