Union-find can be used to find if two elements are in the same set in constant time.
Union-find template
- path compression
- union by rank
Without 2, the query time is O(logn)
With 2, the query time is O(1)
// TODO
Union-find can be used to find if two elements are in the same set in constant time.
Without 2, the query time is O(logn)
With 2, the query time is O(1)
// TODO