which points of a graph are connected?.
Union find, a standard algorithm:
Union_find represents an undirected graph of N points. You can
which points of a graph are connected?.
Union find, a standard algorithm:
Union_find represents an undirected graph of N points. You can
- void connect(int i, int j);
- int find(int i);
- bool equiv(int i, int j) { return find(i) == find(j); }
- Union_find(int sz);
-
-private:
- Array<int> classes;
+ void connect (int i, int j);
+ int find (int i);
+ bool equiv (int i, int j) { return find (i) == find (j); }
+ Union_find (int sz);