int father[
100];
void makeSet() {
for (
int i =
0; i <
100; i++)
father[i] = i;
}
int findRoot(
int x) {
if (father[x] == x)
return x;
else
return findRoot(father[x]);
}
int Find(
int x) {
if (father[x] != x) father[x] = Find(father[x]);
return father[x];
}
int DFind(
int x) {
int root = x;
while (root != father[root]) {
root = father[root];
}
while (x != root) {
int tmp = father[x];
father[x] = root;
x = tmp;
}
return root;
}
void Union(
int x,
int y) {
int a, b;
a = findRoot(x);
b = findRoot(y);
father[a] = b;
}
转载请注明原文地址: https://ju.6miu.com/read-1152717.html