hdu1878

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int f[1005];
int n, m;
int in[1005];

int Find(int x){
	return x == f[x] ? x : Find(f[x]);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	while(scanf("%d", &n) == 1){
		if(!n) break;
		memset(in, 0, sizeof(in));
		scanf("%d", &m);
		for (int i = 1; i <= n; i++) f[i] = i;
		int x, y;
		int flag = 0;
		for (int i = 1; i <= m; i++){
			scanf("%d %d", &x, &y);
			in[x]++, in[y]++;
			int xx = Find(x), yy = Find(y);
			if(xx != yy){
				f[xx] = yy;
			}
		}
		set<int>st;
		for (int i = 1; i <= n; i++){
			f[i] = Find(i);
			st.insert(f[i]);
			if(in[i] % 2 != 0){
				flag = 1;
				break;
			}
		}
		if((int)st.size() != 1) flag = 1;
		printf("%d\n", flag ? 0 : 1);
	}

	return 0;
}
/**/

 

全部评论

相关推荐

斑驳不同:还为啥暴躁 假的不骂你骂谁啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务