UVA10596

#include<stdio.h>
#include<string.h>
#define N 300 

int map[N][N];
int vis[N], degree[N]; 
int n, m, a, b;

void dfs(int u){

	vis[u] = 1;	
	for(int i = 0;i < n; i++)
		if(!vis[i] && map[u][i])	
		{
			dfs(i);		
		}	
	
}//深度遍历,遍历每一个点

int connect(){

	for(int i = 0;i < n; i++)
		if(!vis[i])
			return 0;

	return 1;
}//是否为连通图

int circuit(){

	for(int i = 0;i < n; i++)
		if(degree[i] % 2 != 0)
			return 0;
	return 1;
}//判断是否为欧拉回路

int main(){

	while(scanf("%d %d", &n, &m) != EOF){
		memset(map, 0, sizeof(map));	
		memset(vis, 0, sizeof(vis));	
		memset(degree, 0, sizeof(degree));	
		for(int i = 0;i < m; i++)	
		{
			scanf("%d %d", &a, &b);	
			degree[a]++;
			degree[b]++;	
			map[a][b] = 1;			
			map[b][a] = 1;	
		}	
	
		dfs(0);	
		if(!connect())	
			printf("Not Possible\n");		
	
		else if(!circuit())	
			printf("Not Possible\n");	
	
		else
			printf("Possible\n");	
	}

	return 0;
}
//判断是否为欧拉回路
//要为连通图
//所有点的度数为偶数


你可能感兴趣的:(UVA10596)