public final class UnionFind extends Object
| Constructor and Description |
|---|
UnionFind(int n)
Initializes the disjoint-set data structure.
|
| Modifier and Type | Method and Description |
|---|---|
int |
find(int x)
Finds the set of a given element, and compresses the path to the root node.
|
int |
link(int x,
int y)
Unites two given sets.
|
int |
size() |
int |
union(int p,
int q)
Unites the sets containing the two given elements.
|
public UnionFind(int n)
n - the overall size of the domainpublic int size()
public int union(int p,
int q)
p - the first elementq - the second elementpublic int link(int x,
int y)
x - the first sety - the second setpublic int find(int x)
x - the elementCopyright © 2015. All Rights Reserved.