跳到正文

个人记录

并查集

cyx_20131003约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年8月10日
收录
2026年8月13日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn=1e5+5;
ll n,dad[maxn];
void init(){
	for(ll i=1;i<=n;i++){//初始化 
		dad[i]=i;
	}
}
ll fi(ll x){//查找函数
	if(dad[x]==x){
		return x;
	}
	return dad[x]=fi(dad[x]);
}
void me(ll x, ll y){//合并函数
	dad[fi(x)]=fi(y);
}
int main(){
//  double string a.length() unsigned long long memset(a,0,sizeof(a));
//	freopen("?.in","r",stdin);scanf("%d",&a);
//	freopen("?.out","w",stdout);printf("%d",a);
//  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n;
	init();
	return 0;
}
//㊣
原文