MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / unite

Method unite

code/data-structures/union_find.cpp:4–9  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2 vi p; union_find(int n) : p(n, -1) { }
3 int find(int x) { return p[x] < 0 ? x : p[x] = find(p[x]); }
4 bool unite(int x, int y) {
5 int xp = find(x), yp = find(y);
6 if (xp == yp) return false;
7 if (p[xp] > p[yp]) swap(xp,yp);
8 p[xp] += p[yp], p[yp] = xp;
9 return true; }
10 int size(int x) { return -p[find(x)]; } };
11// vim: cc=60 ts=2 sts=2 sw=2:

Callers 7

testFunction · 0.80
mstFunction · 0.80
testFunction · 0.80
processMethod · 0.80
random_treeFunction · 0.80
sccFunction · 0.80
find_minMethod · 0.80

Calls 1

findFunction · 0.85

Tested by 3

testFunction · 0.64
testFunction · 0.64
random_treeFunction · 0.64