gen-rooted-tree-graph.cpp 711 B

123456789101112131415161718192021222324252627282930
  1. #include "testlib.h"
  2. #include <vector>
  3. using namespace std;
  4. int main(int argc, char *argv[]) {
  5. registerGen(argc, argv, 1);
  6. int n = opt<int>(1);
  7. int t = opt<int>(2);
  8. vector<int> p(n);
  9. // p[i] is the parent of i-th vertex in 0-numeration without shuffling
  10. for (int i = 1; i < n; i++)
  11. p[i] = rnd.wnext(i, t);
  12. vector<int> perm(n);
  13. for (int i = 0; i < n; i++)
  14. perm[i] = i;
  15. shuffle(perm.begin() + 1, perm.end());
  16. vector<int> pp(n - 1);
  17. // pp[i] is the parent of (i+2)-nd vertex in 1-numeration after shuffling
  18. for (int i = 1; i < n; i++)
  19. pp[perm[i] - 1] = perm[p[i]] + 1;
  20. println(n);
  21. println(pp);
  22. }