并查集
cyx_20131003 · · 个人记录
#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;
}
//㊣