main.cpp 693 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <iostream>
  2. #include "disjoint_set.hpp"
  3. #define endl '\n'
  4. using namespace std;
  5. void print(DisjointSet *ds)
  6. {
  7. cout << ds->root(0) << " " << ds->size(0) << " " << ds->root(1) << " " << ds->size(1) << endl;
  8. }
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. auto ds = disjoint_set()->with_undo()->init(2);
  14. print(ds);
  15. ds->merge(0, 1);
  16. print(ds);
  17. ds->undo();
  18. print(ds);
  19. // This disjoint set doesn't build history vector
  20. ds = disjoint_set()->init(2);
  21. print(ds);
  22. ds->merge(0, 1);
  23. print(ds);
  24. // This is runtime error since this disjoint set doesn't implement undo
  25. // ds->undo();
  26. // print(ds);
  27. return 0;
  28. }