Open youngyangyang04 opened 2 months ago
static private int[] father;
static private void init(int n) {
father = new int[n + 1];
for (int i = 1; i <= n; i++) father[i] = i;
}
static private int find(int u) {
if (u == father[u]) return u;
else return find(father[u]);
}
static private void join(int u, int v) {
u = find(u);
v = find(v);
if (u != v) father[v] = u;
}
这里讲的不太行,举的例子也不够好。其实这里的秩不仅仅指树的高度,而是一种抽象表示。这里甚至可以是树的节点数。
https://www.programmercarl.com/kamacoder/%E5%9B%BE%E8%AE%BA%E5%B9%B6%E6%9F%A5%E9%9B%86%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html