BZOJ2079 [Poi2010]Guilds 【贪心】

题目链接

BZOJ2079

题解

题意就是黑白染色,要求相邻点存在不同颜色的点
显然从一个点出发,相邻点如果没有染色,染不同颜色,那么一个联通块一定会满足要求
证明:在\(dfs\)树上,每个点父亲和它不同色
所以只需检查有无孤立的点

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 200005,maxm = 100005,INF = 1000000000;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
	return out * flag;
}
int n,m,de[maxn];
int main(){
	n = read(); m = read(); int a,b;
	while (m--){
		a = read(); b = read();
		if (a != b) de[a]++,de[b]++;
	}
	int flag = true;
	REP(i,n) if (!de[i]){flag = false; break;}
	puts(flag ? "TAK" : "NIE");
	return 0;
}

posted @ 2018-06-28 12:28  Mychael  阅读(93)  评论(0编辑  收藏  举报