文章

82

粉丝

343

获赞

27

访问

660.6k

头像
克鲁斯卡尔
P1312 浙江大学机试题
发布于2021年2月18日 18:20
阅读数 6.8k

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

const int maxn=1e3;
int f[maxn];

struct node{
    int x,y,w;
};

void init(int n){
    for(int i=0;i<=n;i++){
        f[i]=i;
    }
}

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

void merge(int x,int y){
    x=find(x);
    y=find(y);
    if(x!=y){
        f[x]=y;
    }
}

bool cmp(node a,node b){
    return a.w<b.w;
}

bool ok(int m){
    int t;
    for(int i=1;i<=m;i++){
        t=find(i);
    }
    for(int i=1;i<=m;i++){
        if(f[i]!=t){
            ret...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发