| 1 | struct union_find { |
| 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: |
nothing calls this directly
no outgoing calls
no test coverage detected