#include <stdio.h>
#include <stdbool.h>
#include <malloc.h>
#define maxVertexNum 1000
bool visited[maxVertexNum];
typedef int WeightType;
typedef int Vertex;
typedef struct Gnode
{
int nv;
int ne;
WeightType G[maxVertexNum][maxVertexNum];
int Degree[maxVertexNum];
} * MGraph;
typedef struct enode
{
Vertex v, w;
} * Edge;
MGraph create(int n)
{
Vertex v, w;
MGraph Graph = (MGraph)malloc(sizeof(struct Gnode));
Graph->nv = n;
Graph->ne = 0;
for (v = 0; v < Graph->nv; v++)
{
Graph-> Degree[v] = 0;
for (w = 0; w < Graph->nv; w++)
Graph->G[v][w] = 0;
}
return Graph;
}
void insert(MGraph Graph, Edge e)
{
Graph->G[e->v][e->w] = 1;
Graph-> Degree[e->v]++;
Graph->G[e->w][e->v] = 1;
Graph-> Degree[e->w]++;
}
MGraph build()
{
Vertex v;
MGraph Graph;
Edge e;
int i, j;
scanf("%d", &i);
Graph = create(i);
scanf("%d", &(Graph->ne));
if (Graph->ne != 0)
{
e = (Edge)malloc(sizeof(struct enode));
for (j = 0; j < Graph->ne; j++)
{
scanf("%d%d%d", &e->v, &e->w);
e->v--;
e->w--;
insert(Graph, e);
}
}
return Graph;
}
void dfs(MGraph Graph, Vertex v)
{
Vertex w;
visited[v] = true;
for (w = 0; w < Graph->nv; w++)
if (!visited[w] && Graph->G[v][w])
dfs(Graph, w);
}
bool checked(MGraph Graph)
{
Vertex v;
for (v = 0; v < Graph->nv; v++)
if (Graph-> Degree[v] % 2)
return false;
return true;
}
int main()
{
Vertex v;
MGraph Graph = build();
dfs(Graph, 0);
for (v = 0; v < Graph->nv; v++)
if (!visited[v])
break;
if (v < Graph->nv)
return false;
else
printf("%d", checked(Graph));
return 0;
}
运行提示
/usercode/script.sh: line 62: 12 Segmentation fault $output - < "/usercode/inputFile"
错误。。
是不是有什么常识性错误。。
第一次用线上编译器