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

Method union

src/class174/Code05_Lcm1.java:83–100  ·  view source on GitHub ↗
(int x, int y, int a, int b)

Source from the content-addressed store, hash-verified

81 }
82
83 public static void union(int x, int y, int a, int b) {
84 int fx = find(x);
85 int fy = find(y);
86 if (siz[fx] < siz[fy]) {
87 int tmp = fx; fx = fy; fy = tmp;
88 }
89 rollback[++opsize][0] = fx;
90 rollback[opsize][1] = fy;
91 rollback[opsize][2] = siz[fx];
92 rollback[opsize][3] = maxa[fx];
93 rollback[opsize][4] = maxb[fx];
94 if (fx != fy) {
95 fa[fy] = fx;
96 siz[fx] += siz[fy];
97 }
98 maxa[fx] = Math.max(Math.max(maxa[fx], maxa[fy]), a);
99 maxb[fx] = Math.max(Math.max(maxb[fx], maxb[fy]), b);
100 }
101
102 public static void undo() {
103 for (int fx, fy; opsize > 0; opsize--) {

Callers 1

computeMethod · 0.95

Calls 2

findMethod · 0.95
maxMethod · 0.45

Tested by

no test coverage detected