gen-tree-graph.cpp 701 B

12345678910111213141516171819202122232425262728293031
  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. for (int i = 1; i < n; i++)
  10. p[i] = rnd.wnext(i, t);
  11. vector<int> perm = rnd.perm(n);
  12. vector<pair<int, int>> edges;
  13. for (int i = 1; i < n; i++)
  14. if (rnd.next(2))
  15. edges.push_back(make_pair(perm[i], perm[p[i]]));
  16. else
  17. edges.push_back(make_pair(perm[p[i]], perm[i]));
  18. shuffle(edges.begin(), edges.end());
  19. println(n);
  20. for (auto edge: edges)
  21. println(edge.first + 1, edge.second + 1);
  22. }