-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerador.cpp
57 lines (46 loc) · 1.24 KB
/
gerador.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
#include <stdio.h>
#include <stdlib.h>
const int MAX_VER = 20000;
int vertices[MAX_VER];
int arestas[MAX_VER][MAX_VER];
int dist[MAX_VER];
int grau[MAX_VER];
void buildGraph(int ver, int n_are, FILE *out);
void saveGraph(int ver, int are, FILE *out);
int main(int argc, char **argv) {
FILE *out = fopen("ger_in.txt", "w");
int ver, n_are;
printf("Entre com a quantidade de vertices\n");
scanf("%d", &ver);
buildGraph(ver, n_are, out);
return 0;
}
void saveGraph(int ver, int are, FILE *out){
int i, j;
fprintf(out, "%d %d\n", ver, are);
for (i=0; i<ver; i++){
for(j=0; j<ver; j++){
if(arestas[i][j]){
fprintf(out, "%d %d %d\n", i, j, arestas[i][j]);
}
}
}
}
void buildGraph(int ver, int n_are, FILE *out) {
int dest, custo, i, j, are, cont=0;
for (i = 0; i < ver; i++) {
are = (ver*(ver-1));
for (j=0; j < ver; j++) {
if(i!=j){
custo = (rand() % 1000)+1;
// custo = custo+1;
arestas[i][j] = custo;
}
//arestas[dest][i] = custo;
// grau[i]++;
// grau[dest]++;
// cont++;
}
}
saveGraph(ver, are, out);
}