(int x, int y)
| 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) { |