| 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--) { |