/** * The QuickFindUF class represents a union–find data type * (also known as the disjoint-sets data type). * It supports the classic union and find operations, * along with a count operation that returns the total number * of sets. *

* The union-find data type models a collection of sets containing * n elements, with each element in exactly one set. * The elements are named 0 through n–1. * Initially, there are n sets, with each element in its * own set. The cannonical elemement of a set * (also known as the root, identifier, * leader, or set representative) * is one distinguished element in the set. Here is a summary of * the operations: *

*

* The canonical element of a set can change only when the set * itself changes during a call to union—it cannot * change during a call to either find or count. *

* This implementation uses quick find. * The constructor takes Θ(n) time, where n * is the number of sites. * The find, connected, and count * operations take Θ(1) time; the union operation * takes Θ(n) time. *

* For alternative implementations of the same API, see * {@link UF}, {@link QuickUnionUF}, and {@link WeightedQuickUnionUF}. * For additional documentation, see * Section 1.5 of * Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. */ export default class QuickFindUF { private id; private __count; constructor(n: number); /** * Returns the number of components. * * @return the number of components (between `1` and `n`) */ count(): number; /** * Returns the component identifier for the component containing site `p`. * * @param p the integer representing one site * @return the component identifier for the component containing site `p` * @throws IllegalArgumentException unless `0 <= p < n` */ find(p: number): number; private validate; /** * Returns true if the the two sites are in the same component. * * @param p the integer representing one site * @param q the integer representing the other site * @return `true` if the two sites `p` and `q` are in the same component; * `false` otherwise * @throws IllegalArgumentException unless * both `0 <= p < n` and `0 <= q < n` */ connected(p: number, q: number): boolean; /** * Merges the component containing site `p` with the * the component containing site `q`. * * @param p the integer representing one site * @param q the integer representing the other site * @throws IllegalArgumentException unless * both `0 <= p < n` and `0 <= q < n` */ union(p: number, q: number): void; /** * Reads in a sequence of pairs of integers (between 0 and n-1) from standard input, * where each integer represents some site; * if the sites are in different components, merge the two components * and print the pair to standard output. * * @param args the command-line arguments */ static main(): Promise; }