1
0

gen-tree-graph.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "testlib.h"
  2. #include <iostream>
  3. #include <sstream>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <string>
  7. #include <cstdlib>
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <cmath>
  11. #include <ctime>
  12. #include <climits>
  13. #include <cassert>
  14. #include <vector>
  15. #include <queue>
  16. #include <stack>
  17. #include <deque>
  18. #include <set>
  19. #include <map>
  20. #include <bitset>
  21. #include <utility>
  22. #include <algorithm>
  23. #define forn(i, n) for (int i = 0; i < int(n); i++)
  24. using namespace std;
  25. int main(int argc, char* argv[])
  26. {
  27. registerGen(argc, argv, 1);
  28. int n = opt<int>(1);
  29. int t = opt<int>(2);
  30. vector<int> p(n);
  31. forn(i, n)
  32. if (i > 0)
  33. p[i] = rnd.wnext(i, t);
  34. printf("%d\n", n);
  35. vector<int> perm(n);
  36. forn(i, n)
  37. perm[i] = i;
  38. shuffle(perm.begin() + 1, perm.end());
  39. vector<pair<int,int> > edges;
  40. for (int i = 1; i < n; i++)
  41. if (rnd.next(2))
  42. edges.push_back(make_pair(perm[i], perm[p[i]]));
  43. else
  44. edges.push_back(make_pair(perm[p[i]], perm[i]));
  45. shuffle(edges.begin(), edges.end());
  46. for (int i = 0; i + 1 < n; i++)
  47. printf("%d %d\n", edges[i].first + 1, edges[i].second + 1);
  48. return 0;
  49. }