-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.cpp
90 lines (82 loc) · 1.89 KB
/
generate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
#include <fstream>
int main(int argc, char* argv[]) {
if(argc < 4) {
cout << "Usage: ./generate <nodes> <edges> <queries>\n";
exit(-1);
}
long long n = atoi(argv[1]);
long long m = atoi(argv[2]);
long long q = atoi(argv[3]);
if(m > n * n) {
cout << "the fuck\n";
exit(-1);
}
cout << "generating bipartite graph of " << n << " nodes on each side and " << m << " edges\n";
random_device rd;
mt19937 rng(rd());
uniform_int_distribution<> dist(0, n - 1);
ofstream out("graph.txt");
out << n << ' ' << m << '\n';
set<pair<int, int> > in, nin;
if(m > n * n / 2) {
set<pair<int, int> > S;
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
in.insert({i, j});
}
}
while(in.size() != m) {
int x = dist(rng);
int y = dist(rng);
if(in.count({x, y})) {
nin.insert({x, y});
in.erase({x, y});
}
}
for(auto x : in) {
out << x.first << ' ' << x.second << '\n';
}
}
else {
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
nin.insert({i, j});
}
}
while(in.size() != m) {
int x = dist(rng);
int y = dist(rng);
if(in.count({x, y})) continue;
in.insert({x, y});
nin.erase({x, y});
out << x << ' ' << y << '\n';
}
}
// below for generating queries
out << q << '\n';
uniform_int_distribution<> zero_one(0, 1);
uniform_int_distribution<int64_t> del(0, n * n);
for(int i = 0; i < q; i ++) {
int d = zero_one(rng);
if(in.size() > 0 && d == 0) {
int td = del(rng) % in.size();
auto it = in.begin();
advance(it, td);
pair<int, int> t = *it;
in.erase(t);
nin.insert(t);
out << d << ' ' << t.first << ' ' << t.second << '\n';
}
else {
int td = del(rng) % nin.size();
auto it = nin.begin();
advance(it, td);
pair<int, int> t = *it;
nin.erase(t);
in.insert(t);
out << d << ' ' << t.first << ' ' << t.second << '\n';
}
}
}