MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / union

Method union

src/class197/Code05_Boolean1.java:56–70  ·  view source on GitHub ↗
(int x, int y)

Source from the content-addressed store, hash-verified

54 }
55
56 public static void union(int x, int y) {
57 int fx = find(x);
58 int fy = find(y);
59 if (fx != fy) {
60 if (siz[fx] < siz[fy]) {
61 int tmp = fx;
62 fx = fy;
63 fy = tmp;
64 }
65 fa[fy] = fx;
66 siz[fx] += siz[fy];
67 rollback[++opsize][0] = fx;
68 rollback[opsize][1] = fy;
69 }
70 }
71
72 public static void undo(int oldsiz) {
73 while (opsize > oldsiz) {

Callers 1

computeMethod · 0.95

Calls 1

findMethod · 0.95

Tested by

no test coverage detected