-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path2021_code_graph.cpp
More file actions
45 lines (45 loc) · 1.02 KB
/
2021_code_graph.cpp
File metadata and controls
45 lines (45 loc) · 1.02 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
#include <stdio.h>
#include <stdlib.h>
#define MAXV 5
typedef struct {
int numVertices, numEdges;
char VerticesList[MAXV];
int Edge[MAXV][MAXV];
}MGraph;
int IsExistEL(MGraph G) {
int oddCount = 0;
for (int i = 0;i < G.numVertices;i++) {
int tmpOdd = 0;
for (int j = 0;j < G.numVertices;j++) {//遍历每一行,将个数统计出来
tmpOdd += G.Edge[i][j];
}
if (tmpOdd % 2 == 1) {//如果个数是奇数,就将oddCount+1
oddCount++;
if (oddCount > 2) {
return 0;
}
}
}
if (oddCount == 0 || oddCount == 2)return 1;
else return 0;
}
void setG(MGraph* g, int a[]) {
for (int i = 0;i < MAXV * MAXV;i++) {
g->Edge[i / 5][i % 5] = a[i];
}
}
int main() {
MGraph G;
G.numVertices = 5;
int a[] = {
1,1,0,0,1,//
1,0,1,0,1,//
0,1,0,1,1,//
0,0,1,0,1,//
0,0,0,1,0,//
};
setG(&G, a);
int i = IsExistEL(G);
printf("%d", i);
return 0;
}