diff options
author | Ta180m | 2020-06-14 11:15:37 -0500 |
---|---|---|
committer | Ta180m | 2020-06-14 11:15:37 -0500 |
commit | 6cc7940d64234fc361629a5e1578c23a5c46266d (patch) | |
tree | 3fb09ea3e190f4f674b6048b3eaca58c39cc673f /Data Structures | |
parent | 4405a5c45ed85e7f8e2c4c090bb45dbf82537507 (diff) |
update
Diffstat (limited to 'Data Structures')
-rw-r--r-- | Data Structures/union-find_disjoint_set.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Data Structures/union-find_disjoint_set.cpp b/Data Structures/union-find_disjoint_set.cpp index d81a734..b47139f 100644 --- a/Data Structures/union-find_disjoint_set.cpp +++ b/Data Structures/union-find_disjoint_set.cpp @@ -9,8 +9,8 @@ public: 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); } void union_set(int i, int j) { - if (same_set(i, j)) return; int x = find_set(i), y = find_set(j); + if (x == y) return; rank[x] > rank[y] ? p[y] = x : p[x] = y; if (rank[x] == rank[y]) rank[y]++; } |