#博弈论,贪心#AT2376 [AGC014D] Black and White Tree
题目传送门
分析
考虑到先手放一个白点后手必将在相邻位置放一个黑点,
如果没有合适的位置放黑点先手必胜,也就是问是否存在完美匹配,
直接从叶子节点到根贪心匹配即可
代码
#include
#include
using namespace std;
const int N=100011;
struct node{int y,next;}e[N<<1];
int v[N],as[N],et=1,n,flag;
int iut(){
int ans=0; char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=ans*10+c-48,c=getchar();
return ans;
}
void dfs(int x,int fa){
for (int i=as[x];i;i=e[i].next)
if (e[i].y!=fa) dfs(e[i].y,x);
if (!v[x]){
if (v[fa]) flag=1;
v[x]=v[fa]=1;
}
}
int main(){
n=iut(),v[0]=1;
for (int i=1;i