Update union-find_disjoint_set.cpp

This commit is contained in:
Anthony Wang 2020-09-05 17:17:25 -05:00
parent 9f56b8f9fb
commit a9bc65e2c8

View file

@ -2,9 +2,9 @@ class UFDS {
private: vector<int> p, rank;
public:
UFDS(int N) {
p.assign(N + 1, 0);
p.assign(N+1, 0);
for (int i = 0; i <= N; i++) p[i] = i;
rank.assign(N + 1, 0);
rank.assign(N+1, 0);
}
int find_set(int i) { return (p[i] == i) ? i : (p[i] = find_set(p[i])); }
bool same_set(int i, int j) { return find_set(i) == find_set(j); }