Update union-find_disjoint_set.cpp
This commit is contained in:
parent
9f56b8f9fb
commit
a9bc65e2c8
|
@ -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); }
|
||||
|
@ -14,4 +14,4 @@ public:
|
|||
rank[x] > rank[y] ? p[y] = x : p[x] = y;
|
||||
if (rank[x] == rank[y]) rank[y]++;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue