题目连接 点击打开链接
本题主要考察欧拉回路的两个充要条件:1.联通图 2.顶点度数都为偶数 (两个条件缺一不可)
联通性-------->深搜
顶点度数-----> degree[i] % 2 != 0 ;
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n, m;
int mymap[1000 + 10][1000 + 10];
int degree[1000 + 10];
int visited[1000 +10];
void DFS(int x, int n)
{
visited[x] = 1;
for (int i = 1; i <= n; i++)
{
if (visited[i] == 0 && mymap[x][i])
{
DFS(i, n);
}
}
}
int main()
{
while (scanf("%d %d", &n, &m)!=EOF && n)
{
memset(mymap, 0, sizeof(mymap));
memset(visited, 0, sizeof(visited));
memset(degree, 0, sizeof(degree));
while (m--)
{
int a, b;
scanf("%d %d", &a, &b);
mymap[a][b] = mymap[b][a] = 1;
degree[a]++;
degree[b]++;
}
DFS(1, n);
int flag = 1;
for (int i = 1; i <= n; i++)
{
if(visited[i] == 0)
{
flag = 0;
break;
}
if(degree[i] % 2 != 0)
{
flag = 0;
break;
}
}
if(flag)
{
printf("1\n");
}
else
{
printf("0\n");
}
}
return 0;
}