-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandom_graph_generator.cpp
executable file
·56 lines (46 loc) · 1.02 KB
/
random_graph_generator.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
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[])
{
if (argc < 4)
{
cout << "Usage: " << argv[0] << " <graph_file_name>" << " <n>" << " <m>\n";
return 0;
}
int n, m;
int x, y;
/*cout << "Enter number of nodes: ";
cin >> n;
cout << "Enter number of edges: ";
cin >> m;
*/
n = atoi(argv[2]);
m = atoi(argv[3]);
freopen(argv[1], "w", stdout);
cout << n << " " << m << endl;
vector<int> *v = new vector<int>[n+1];
// srand(time(0));
for (int i = 0; i < m; i++) {
do {
x = rand() % n;
y = rand() % n;
} while (x == y);
// Edge between x and y
v[x].push_back(y);
v[y].push_back(x);
}
// R
cout << "0 ";
int cur = 0;
for(int i=0; i<n; i++) {
cur += v[i].size();
cout << cur << " ";
}
cout << endl;
// C
for(int i=0; i<n; i++)
for(int it : v[i])
cout << it << " ";
cout << endl;
delete[] v;
}