1
0

gen-rooted-tree-graph.cpp 733 B

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