Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <utility>
- #include <functional>
- #include <vector>
- #include <utility>
- #include <random>
- #include <iostream>
- using namespace std;
- //-----Tooster-----
- int n, maxChildCount, firstVertex;
- int main(int argc, char *argv[]) {
- ios_base::sync_with_stdio(false);
- if (argc == 1) {
- int a;
- cin >> a >> n >> maxChildCount >> firstVertex;
- srand(atoi("treegen") + a);
- }
- else if (argc == 5) {
- srand(atoi(argv[0]) + atoi(argv[1]));
- n = atoi(argv[2]);
- maxChildCount = atoi(argv[3]);
- firstVertex = atoi(argv[4]);
- }
- else {
- cerr << "Usage: <randomSeed> <vertices> <maxChildCount> <firstVertex>" << endl;
- cerr << " randomSeed - seed for random number generator, e.g. test number" << endl;
- cerr << " vertices - number of vertices" << endl;
- cerr << " maxChildCount - maximum number of edges connected to one vertex" << endl;
- cerr << " firstVertex - vertices enumeration start" << endl;
- cerr << endl;
- cerr << " output format: N pairs {A, B} : A is connected with bidirectional edge with B" << endl;
- return 1;
- }
- vector<vector <int> > V(n);
- vector<int> hashTable(n);
- for (int i = 0; i < n; i++) hashTable[i] = i;
- random_shuffle(hashTable.begin(), hashTable.end());
- int v = 1;
- while (v < n) {
- int u = rand() % v;
- int children = rand() % maxChildCount + 1;
- while (v < n && children > 0 && V[u].size() < maxChildCount - 1) {
- V[u].push_back(v++);
- children--;
- }
- }
- for (int i = 0; i < V.size(); i++)
- for (int j = 0; j < V[i].size(); j++)
- cout << hashTable[i] + firstVertex << " " << hashTable[V[i][j]] + firstVertex << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement