|
@@ -15,23 +15,39 @@ int main()
|
|
|
ios_base::sync_with_stdio(0);
|
|
|
cin.tie(0);
|
|
|
|
|
|
+ // Creates a disjoint set that allows undo last action.
|
|
|
+ // It creates a separate array history to allow this.
|
|
|
auto ds = disjoint_set()->with_undo()->init(2);
|
|
|
print(ds);
|
|
|
+ // 0 | root 0 | size 1
|
|
|
+ // 1 | root 1 | size 1
|
|
|
|
|
|
ds->merge(0, 1);
|
|
|
print(ds);
|
|
|
+ // 0 | root 1 | size 2
|
|
|
+ // 1 | root 1 | size 2
|
|
|
|
|
|
ds->undo();
|
|
|
print(ds);
|
|
|
+ // 0 | root 0 | size 1
|
|
|
+ // 1 | root 1 | size 1
|
|
|
|
|
|
- // This disjoint set doesn't build history vector
|
|
|
+ // This disjoint set doesn't allow to undo (it doesn't build history vector)
|
|
|
+ // but has the same base type that the former disjoint set. It can be passed
|
|
|
+ // to the same function and they expose the same api ...
|
|
|
+ // with some caveat see below
|
|
|
ds = disjoint_set()->init(2);
|
|
|
print(ds);
|
|
|
+ // 0 | root 0 | size 1
|
|
|
+ // 1 | root 1 | size 1
|
|
|
|
|
|
ds->merge(0, 1);
|
|
|
print(ds);
|
|
|
+ // 0 | root 1 | size 2
|
|
|
+ // 1 | root 1 | size 2
|
|
|
|
|
|
- // This is runtime error since this disjoint set doesn't implement undo
|
|
|
+ // Caveat: This disjoint expose undo function, but it will throw an error if
|
|
|
+ // used since it is not really available.
|
|
|
// ds->undo();
|
|
|
// print(ds);
|
|
|
|