// 浙大2008机试
//
// 欧拉回路
// 充要条件:1.连通;2.每个点的度为偶数
// 连通:一次dfs后,所有的点都标记为已访问。
//
//
#include <stdio.h>
#include <cstring>
#include <stdlib.h>
#include <cctype>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#define SIZE 1005
using namespace std;
//--------------------
int graph[SIZE][SIZE];
int degree[SIZE];
bool visited[SIZE];
int m, n;
//--------------------
void Init()
{
memset(graph, 0, sizeof(graph));
memset(degree, 0, sizeof(degree));
memset(degree, 0, sizeof(degree));
m=0;
}
void Input()
{
scanf("%d", &m);
int i, x, y;
for(i=0; i<m; i++)
{
scanf("%d%d", &x, &y);
graph[x][y] = graph[y][x] = 1;
degree[x]++;
degree[y]++;
}
}
void dfs(int x)
{
visited[x] = 1;
for(int i=1; i<=n; i++)
{
if(graph[x][i] == 1 && visited[i] == 0) //访问相连的并且没有访问的节点
{
dfs(i);
}
}
return ;
}
bool Conn()
{
for(int i=1; i<=n; i++)
{
if(visited[i] == 0)
return false;
}
return true;
}
bool Oushu()
{
for(int i=1; i<=n; i++)
{
if(degree[i] % 2 != 0)
return false;
}
return true;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("E:\\in.txt", "r", stdin);
#endif
while(scanf("%d", &n) && n)
{
Init();
Input();
dfs(1);
if( Conn() && Oushu())
{
printf("1\n");
}
else
{
printf("0\n");
}
}
return 0;
}
九度:1027<欧拉回路><搜索>
最新推荐文章于 2020-10-28 22:29:52 发布