Update trees/quick_union.cc
Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
parent
1629a9f47f
commit
9a8c1277fb
|
@ -1,9 +1,10 @@
|
|||
class quick_union {
|
||||
private:
|
||||
vector<size_t> c;
|
||||
vector<size_t> c, sz;
|
||||
public:
|
||||
quick_union(size_t n) : c(n) {
|
||||
quick_union(size_t n) : c(n), sz(n) {
|
||||
iota(c.begin(), c.end(), 0);
|
||||
sz.assign(n, 1);
|
||||
}
|
||||
|
||||
size_t query(size_t i) {
|
||||
|
@ -12,11 +13,15 @@ public:
|
|||
}
|
||||
|
||||
void merge(size_t i, size_t j) {
|
||||
sz[query(j)] += sz[query(i)];
|
||||
c[query(i)] = query(j);
|
||||
}
|
||||
|
||||
bool connected(size_t i, size_t j) {
|
||||
return query(i) == query(j);
|
||||
}
|
||||
};
|
||||
|
||||
size_t query_size(size_t i) {
|
||||
return sz[query(i)];
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue