-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_mod.c
More file actions
129 lines (116 loc) · 3.13 KB
/
Copy pathgraph_mod.c
File metadata and controls
129 lines (116 loc) · 3.13 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdio.h>
#include <stdlib.h>
void Max_power(int e, int v, int matr[v][e]){
int verse = -1, power = -1,temp_zero = 0,check = 0,memory = -1;
int temp_matr[v];
for(int i = 0; i < v; ++i ){
temp_matr[i] = 0;
}
for(int i = 0; i < e; ++i){
temp_zero=0;
check=0;
for(int j = 0; j < v; ++j){
if(matr[j][i] != 0){
++temp_matr[j];
++check;
if (check == 1 ){
memory = j;
}else{
memory = -1;
}
}
else{
temp_zero += 1;
}
if (temp_zero == v-1 && check == 1 ){
++temp_matr[memory];
}
}
}
for(int i = 0; i<v; ++i ){
if (temp_matr[i]>power){
power = temp_matr[i];
verse = i;
}
}
printf("Max power of verse %d is %d ",verse,power);
}
int main(void) {
int e = 0, v = 0,ans1 = 0,ans2 = 0;
printf("Enter edges and verses of graph:\nV=");
scanf("%d", &v);
printf("\nE=");
scanf("%d", &e);
printf("Graph is directed:\n 1 - yes\n 0 - no\n answer: ");
scanf("%d",&ans1);
printf("Graph is weighted:\n 1 - yes\n 0 - no\n answer: ");
scanf("%d",&ans2);
int* edge = NULL;
if(ans2){
edge = (int*)malloc(e*sizeof(int));
for (int i=0;i<e;++i){
printf("\ne%d=",i+1);
scanf("%d", &edge[i]);
}
}
int matr[v][e];
for(int i = 0; i < v; ++i){
for(int j = 0; j < e; ++j){
scanf("%d",&matr[i][j]);
}
}
Max_power(e,v,matr);
FILE *gfile = fopen("C:\\Users\\Timur\\Desktop\\gfile.dot","w+");
if(gfile == NULL){
printf("File is not exist or not created");
return 0;
};
if(ans1){fprintf(gfile, "digraph graphname {\n");}
else{fprintf(gfile, "graph graphname {\n");}
for(int i=0;i<v;++i){
fprintf(gfile,"\t%d;\n",i);
}
for (int i = 0; i < e; ++i){
int first = -1, second = -1;
for (int j = 0; j < v; ++j){
if (matr[j][i]){
if (ans1){
if(matr[j][i] == -1){
second = j;
} else {
first = j;
}
} else {
if (first + 1){
second = j;
} else {
first = j;
}
}
}
}
fprintf(gfile, "\t%d -", first);
if(ans1){
fputc('>', gfile);
} else {
fputc('-', gfile);
}
if (second != -1)
fprintf(gfile," %d", second);
else
fprintf(gfile," %d", first);
if(ans2){
fprintf(gfile, "[label=%d]", edge[i]);
}
fprintf(gfile,";\n");
}
fprintf(gfile, "}");
fclose(gfile);
if(e>(((v-1)*(v-2))/2)){
printf("\nGraph is connected");
}else{
printf("\nGraph is not connected");
}
system("dot -Tpng gfile.dot -o graph.png");
return 0;
}